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?
You can use this regex /^[ A-Za-z0-9_@./#&+-]*$/.
To match any character except a list of excluded characters, put the excluded charaters between [^ and ] . The caret ^ must immediately follow the [ or else it stands for just itself. The character '. ' (period) is a metacharacter (it sometimes has a special meaning).
use:
/^[ A-Za-z0-9_@./#&+-]*$/
You can also use the character class \w to replace A-Za-z0-9_
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 /
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With