By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,814 Members | 2,183 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,814 IT Pros & Developers. It's quick & easy.

Special Character If Condition

P: 4
The following code works fine:

if (newPassword.match(/(.*[~,!,@,#,$,%,^,&,*,(,),_,+,{,},|,:,\,",<,>,?,`,-,=,\,;,',,,.,/].*[~,!,@,#,$,%,^,&,*,(,),_,+,{,},|,:,\,",<,>,?,`,-,=,\,;,',,,.,/])/))

but when I include " [ , ] , " in it I get an error. Anyone know how I can include " [ " and " ] " in the condition without getting the error?
Aug 8 '08 #1
Share this Question
Share on Google+
2 Replies

P: 4
I also need to write a condition for checking spaces as well.
Aug 8 '08 #2

Expert Mod 15k+
P: 16,027
You need to escape special characters with a backslash.

Instead of trying to match non-valid characters, why not match valid characters instead?
Aug 8 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.