javascript regex for special characters

前端 未结 12 806
囚心锁ツ
囚心锁ツ 2020-11-29 22:28

I\'m trying to create a validation for a password field which allows only the a-zA-Z0-9 characters and .!@#$%^&*()_+-=

I can\'t seem to

12条回答
  •  鱼传尺愫
    2020-11-29 23:06

    This regex works well for me to validate password:

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

    This list of special characters (including white space and punctuation) was taken from here: https://www.owasp.org/index.php/Password_special_characters. It was changed a bit, cause backslash ('\') and closing bracket (']') had to be escaped for proper work of the regex. That's why two additional backslash characters were added.

提交回复
热议问题