javascript regex for special characters

前端 未结 12 789
囚心锁ツ
囚心锁ツ 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 22:45

    a sleaker way to match special chars:

    /\W|_/g
    

    \W Matches any character that is not a word character (alphanumeric & underscore).

    Underscore is considered a special character so add boolean to either match a special character or _

提交回复
热议问题