How to write a Regex that allow all the alphanumeric and specific special characters i.e , " ; ! ( ) & '.? [duplicate]
I have a Javascript regex like this:
/^[\x00-\x7F]*$/
I want to modify this regex so that it accept all capital and non-capital alphabets, all the numbers and some special characters: - , _, @, ., /, #, &, +
.
How can I do this?
Solution 1:
use:
/^[ A-Za-z0-9_@./#&+-]*$/
You can also use the character class \w to replace A-Za-z0-9_
Solution 2:
I forgot to mention. This should also accept whitespace.
You could use:
/^[-@.\/#&+\w\s]*$/
Note how this makes use of the character classes \w
and \s
.
EDIT:- Added \ to escape /