I have requirement to allow alphanumeric and certain other characters for a field. I am using this regular expression:
"^[a-zA-Z0-9!@#$&()-`.+,/\"]*$".
The allowed special characters are! @ # $ & ( ) - ‘ . / + , “
But when I test the pattern with a string “test_for_extended_alphanumeric” , the string passes the test. I don’t have "_" allowed in the pattern. What am I doing wrong?
You need to escape the hyphen:
If you don’t escape it then it means a range of characters, like
a-z.