简体   繁体   English

以字母开头的正则表达式包含一个大写/一个小写字母,一个数字,没有特殊字符和最少8个字符

[英]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: 我想写一个正则表达式:

  • starts with a letter 以一封信开头
  • contains one uppercase and one lowercase letter 包含一个大写和一个小写字母
  • contains one number 包含一个数字
  • does not allow special characters 不允许使用特殊字符
  • minimum 8 characters 最少8个字符

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.

相关问题 正则表达式,用于最少8个字符,一个大写字母和至少一个数字(不在字符串的开头和结尾) - Regex for min 8 characters, one uppercase letter and min one number not on the beginning and the end of the string 最少 6 个字符的密码 REGEX,至少一个字母和一个数字,可以包含特殊字符 - Password REGEX with min 6 chars, at least one letter and one number and may contain special characters 插入一个大写字母时,Sequelize返回小写字母? - Sequelize returns lowercase letter when inserting a one letter uppercase letter? 正则表达式:必须至少包含一个数字和字母,但不能包含其他字符/空格 - RegEx: Must have at least one number and letter but no other characters / whitespace 正则表达式接受最少6个字符,至少一个字母和以下至少之一:0123456789-。@ _ - Regex to accept Min 6 characters, at least one letter and at least one of the following: 0123456789-.@_ 密码的正则表达式必须至少包含八个字符,至少一个数字以及大小写字母和特殊字符 - Regex for password must contain at least eight characters, at least one number and both lower and uppercase letters and special characters 检查一个字符串是以一个字母开头,后跟数字,然后是任何字符 - Check if a string starts with one letter followed by digit(s) and then any characters 正则表达式不起作用-至少8个字符,1个数字,1个特殊字符和1个大写字母 - Regex not working - min 8 character, 1 Number, 1 special character and 1 uppercase letter 使字符串中的一个字母小写,所有其他字母大写 - Making one letter in a string lowercase and all other letters uppercase 一个字母和三个数字的正则表达式 - regex for one letter and three number
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM