[英]Regex that starts with letter, contains one uppercase/one lowercase letter, one number and no special characters & min 8 characters
I am trying to write a regex that: 我想写一个正则表达式:
So far I have the upper/lowercase conditions, the number and minimum character requirements set with the following regex: 到目前为止,我有大写/小写条件,使用以下正则表达式设置的数字和最小字符要求:
/^(?=.*?[a-z])(?=.*?[A-Z])(?=.*?[0-9]).{8,}$/
My best guess at resolving the starts with a letter
and does not allow special characters
requirements are below. 我最好
starts with a letter
解决一下starts with a letter
并且does not allow special characters
要求如下。 This regex seems to evaluate all input to false
: 这个正则表达式似乎将所有输入都评估为
false
:
/^[a-zA-Z](?=.*?[a-z])(?=.*?[A-Z])(?=.*?[0-9]).{8,}$/
You need to put the lookaheads after ^
and put [a-zA-Z]
right after them and quantify the rest with {7,}
: 您需要在
^
之后放置前瞻,然后将[a-zA-Z]
放在它们之后,用{7,}
量化其余部分:
^(?=.*?[a-z])(?=.*?[A-Z])(?=.*?[0-9])[a-zA-Z][a-zA-Z0-9]{7,}$
See the regex demo . 请参阅正则表达式演示 。
Pattern details : 图案细节 :
^
- start of a string ^
- 字符串的开头 (?=.*?[az])
- at least 1 lowercase ASCII letter (?=.*?[az])
- 至少1个小写ASCII字母 (?=.*?[AZ])
- at least 1 uppercase ASCII letter (?=.*?[AZ])
- 至少1个大写ASCII字母 (?=.*?[0-9])
- at least 1 ASCII digit (?=.*?[0-9])
- 至少1个ASCII数字 [a-zA-Z]
- an ASCII letter [a-zA-Z]
- ASCII字母 [a-zA-Z0-9]{7,}
- 7 or more ASCII letters or digits ( \\w
also allows _
) [a-zA-Z0-9]{7,}
- 7个或更多ASCII字母或数字( \\w
也允许_
) $
- end of string. $
- 结束字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.