开发者

Regular Expression for password

I'm not really good at regular expressions. I need to do the following to validate if a password, entered by the user, is correct or not.

Criteria:

  1. Must contain at least one number
  2. Must contain at least one letter from A-Z or a-z (case does not matter as long as they enter is a lett开发者_如何学Pythoner).
  3. The password must be a minimum of 8 characters


(?=.*\d)(?=.*[A-Za-z]).{8,}

The first part ((?=.*\d)) searches for at least one number, the second part ((?=.*[A-Za-z])) searches for at least one letter, and the last part (.{8,}) ensures it's at least 8 characters long.

You might want to put an upper limit on the length of the password like this:

^(?=.*\d)(?=.*[A-Za-z]).{8,30}$

The 30 in that spot limits it to 30 characters in length, and the ^ and $ anchor it to the start and end of the string.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜