我需要以下正则表达式模式来验证用户名和密码:
用户名:
- 长度为3到25个字符
- 至少包含一个字符[a-zA-Z]
- 包含任何字符,如:0-9,a-z,A-Z,_
我使用了以下模式,但是我无法确定如何设置{3,25}(我的测试尚未验证它):
^[a-zA-Z0-9_]*[a-zA-Z][a-zA-Z0-9_]*{3,25}$
密码:
* ^ # start-of-string
* (?=.*[0-9]) # a digit must occur at least once
* (?=.*[a-z]) # a lower case letter must occur at least once
* (?=.*[A-Z]) # an upper case letter must occur at least once
* (?=.*[a-zA-Z]) # any letter upper or lower case
* (?=.*[@#$%^&+=]) # a special character must occur at least once
* (?=\\S+$) # no whitespace allowed in the entire string
* .{6,} # anything, at least six places though
* $ # end-of-string
*/
private Pattern VALID_PASSWORD = Pattern.compile("^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[a-zA-Z])(?=.*[@#$%^&+!?=])(?=\\S+$).{6,}$");
我只需要更改这个模式,以允许特殊字符,但我不想让它们成为必需品。
(?=.{3,25}$)
相同的机制,或者匹配\S{3,25}
。 - The fourth bird