开发者

Regular expressions for password validation

开发者 https://www.devze.com 2023-04-01 13:42 出处:网络
I need to validate a password that matches the following criteria: minimum 8 characters contain a combination of numbers and letters

I need to validate a password that matches the following criteria:

  • minimum 8 characters
  • contain a combination of numbers and letters
  • must not enforce special characters

The follow regular expression is what I came up with:

^{8,}.(?=*\d)(?=.*[a-zA-Z])&

but this is failing on:

  • !password1
  • password1
  • Password1

From what I can gather, trying to investigate RegEx, {8,} means minimum of 8 and don't care about the maximum, \d specifies digits, whitespaces and special characters. The a-z make开发者_C百科s sense.


Try:

^(?=.*\d)(?=.*[a-zA-Z]).{8,}$

See it @work


simple not most efficient way:

^[a-zA-Z0-9!.-_]{8,}$

Replace !.-_ with the list of special characters you'd like to allow

0

精彩评论

暂无评论...
验证码 换一张
取 消