I need regex to search string for alphanumeric, (, ), -, ., / and ampersand(&).

Right now i m using this regex in client side validation

 [^A-Za-z0-9.)(/-\&] 

EDIT:

I want to search my string for special characters VAL.search(/[^A-Za-z0-9.)(/-\&]+/g)==-1

2

2 Answers

Escape the backslash, put the dash at the end of the character class.

[^A-Za-z0-9.)(/\\&-] 

Not sure why you included ^, as this negates the character class.

9

Try this:

VAL.search(/[^a-zA-Z0-9.()/&-]/g) == -1 
2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.