简体   繁体   English

密码验证字段的正则表达式

[英]Regex for Password Validation Field

I'm trying to validate a password in my application by using Regex .我正在尝试使用Regex在我的应用程序中验证密码。 I don't have much idea of Regex, This is what i got.我对正则表达式不太了解,这就是我得到的。

"^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$"

This expression is also checking Special Character , and 1 upper case character in password.此表达式还检查Special Character和密码中的 1 个大写字符。

I need a Regex that full fills following criteria.我需要一个完全符合以下标准的正则表达式。

  1. Password Must be at least 8 characters Long.密码长度必须至少为 8 个字符。
  2. Password must contain 1 Letter密码必须包含 1 个字母
  3. Password must contain 1 Number密码必须包含 1 个数字
  4. Password should not contain any special Character.密码不应包含任何特殊字符。

I won't claim to be a regex master, but for the password criteria you describe, you could use:我不会声称自己是正则表达式大师,但对于您描述的密码标准,您可以使用:

/^(?=.*?[a-zA-Z])(?=.*\\d)([a-zA-Z0-9])+$/ to test for conditions 2, 3, and 4. /^(?=.*?[a-zA-Z])(?=.*\\d)([a-zA-Z0-9])+$/测试条件 2、3 和 4。

For condition 1, I would just check the string length property to make sure it's at least 8 characters.对于条件 1,我只会检查字符串长度属性以确保它至少为 8 个字符。

Note that in your current regex, you are requiring at least one uppercase letter, at least one lowercase letter, at least one digit, and at least one of the specified special characters (#?!@$%^&*-).请注意,在您当前的正则表达式中,您需要至少一个大写字母、至少一个小写字母、至少一位数字和至少一个指定的特殊字符 (#?!@$%^&*-)。 Hope this helps.希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM