Special Character If Condition

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shatterah
    New Member
    • Aug 2008
    • 4

    Special Character If Condition

    The following code works fine:

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

    but when I include " [ , ] , " in it I get an error. Anyone know how I can include " [ " and " ] " in the condition without getting the error?
  • shatterah
    New Member
    • Aug 2008
    • 4

    #2
    I also need to write a condition for checking spaces as well.

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      You need to escape special characters with a backslash.

      Instead of trying to match non-valid characters, why not match valid characters instead?

      Comment

      Working...