Regex for allowing character, numbers and - in javascript

hud

I have a textbox where I want user to only input values like below example

I-MH-NGPR-UBR-0001

It means, a user can add only numbers, alphabets and -. Other than this it should not allow user to enter anything.

How to do this in javascript

Rizwan M.Tuman

You can try this:

^[a-zA-Z0-9-]+$

Demo

const regex = /^[a-zA-Z0-9-]+$/m;
const str = `I-MH-NGPR-UBR-0001`;
if (str.match(regex))
  console.log("matched");
else
   console.log("not matched");

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Regex allowing a space character in Java

Java regex allowing all character expect `

Regex for validating passwith allowing specific special character

Regex in c# for allowing numbers and alphabets

Regex for allowing numbers without leading and ending 0

Regex for only allowing letters, numbers, space, commas, periods?

Regex for allowing 4 numbers(of any length) in input field

Javascript Regex optional character

Regex to replace character in Javascript

Javascript - Regex for allowing only selected special characters only

Javascript regex formatter for now allowing a number having , and . at the same time

Regex for allowing just single comma separated values in javascript

How To Ignore An Character With Random Numbers Using RegEx?

Regex to remove everything but numbers and one character

Regex to match numbers followed by a specific character

Regex in JS: find a string of numbers that are preceded by a character

python regex: replace numbers with a special character

Regex for splitting at every character but keeping numbers together

Regex to not match numbers followed by a certain character

Match numbers or first letter before a character - regex

Regex for a range of numbers and one character for validation

replace regex character if it has numbers in front of it

Regex match a sequence of numbers and a character . between them

RegEx to find if string has first a character and then numbers

Regex - Match all numbers after a character

Only allowing octal numbers

Javascript - Create Regex Character Class

Javascript regex in with special character in between

Javascript regex special character not working

TOP Ranking

HotTag

Archive