[英]Java Regex for password validation
I have created regex for password validation in a Java app. 我已经在Java应用程序中创建了用于密码验证的正则表达式。 The regex I created is below for below requirement.
我为以下需求创建的正则表达式如下。
^[\\p{Alnum}#.!@$*&_]{5,12}$
I am missing 1 and 2 like if I give "gjsajhgjhagfj" or "29837846876", it should fail. 我缺少1和2,就像如果我给“ gjsajhgjhagfj”或“ 29837846876”一样,它应该失败。 But it's not happening.
但这没有发生。
Could anyone help please? 有人可以帮忙吗?
You can use lookaheads to force conditions 1 & 2: 您可以提前使用条件1和2:
^(?i)(?=.*[a-z])(?=.*[0-9])[a-z0-9#.!@$*&_]{5,12}$
(?i)
is for insensitive match, the same as Pattern.CASE_INSENSITIVE
flag for your compile function: (?i)
用于不敏感的匹配,与您的编译函数的Pattern.CASE_INSENSITIVE
标志相同:
Pattern.compile(regex, Pattern.CASE_INSENSITIVE)
You can read more about Lookaheads HERE 您可以在此处详细了解Lookaheads
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.