简体   繁体   English

密码正则表达式中的问题

[英]Issues in password regular expression

Hi all I am making a password regular expression in javascript test() method, It will take the following inputs 大家好,我正在javascript test()方法中制作一个密码正则表达式,它将接受以下输入

solution

/^(?=.*\d)^(?=.*[!#$%'*+\-/=?^_{}|~])(?=.*[A-Z])(?=.*[a-z])\S{8,15}$/gm

  1. May contains any letter except space 可能包含除空格以外的任何字母

  2. At least 8 characters long but not more the 15 character 至少8个字符,但不超过15个字符

  3. Take at least one uppercase and one lowercase letter 至少接受一个大写字母和一个小写字母

  4. Take at least one numeric and one special character 至少使用一个数字和一个特殊字符

But I am not able to perform below task with (period, dot, fullStop) 但是我无法使用(句点,点,fullStop)执行以下任务

(dot, period, full stop) provided that it is not the first or last character, and provided also that it does not appear two or more times consecutively. (点,句号,句号),前提是它不是第一个字符或最后一个字符,并且还不能连续出现两次或多次。

Can anyone one help me to sort out this problem, Thanks in advance 谁能帮我解决这个问题,谢谢

You may move the \\S{8,15} part with the $ anchor to the positive lookahead and place it as the first condition (to fail the whole string if it has spaces, or the length is less than 8 or more than 15) and replace that pattern with [^.]+(?:\\.[^.]+)* consuming subpattern. 您可以将带有$锚点的\\S{8,15}部分移至正向前移并将其放置为第一个条件(如果整个字符串有空格,或者长度小于8或大于15,则使整个字符串失败)并将该模式​​替换为[^.]+(?:\\.[^.]+)*消耗子模式。

/^(?=\S{8,15}$)(?=.*\d)(?=.*[!#$%'*+\/=?^_{}|~-])(?=.*[A-Z])(?=.*[a-z])[^.]+(?:\.[^.]+)*$/

See the regex demo 正则表达式演示

Details : 详细资料

  • ^ - start of string ^ -字符串的开头
  • (?=\\S{8,15}$) - the first condition that requires the string to have no whitespaces and be of 8 to 15 chars in length (?=\\S{8,15}$) -第一个条件,要求字符串没有空格并且长度为8到15个字符
  • (?=.*\\d) - there must be a digit after any 0+ chars (?=.*\\d) -任何0+字符后必须有一个数字
  • (?=.*[!#$%'*+\\/=?^_{}|~-]) - there must be one symbol from the defined set after any 0+ chars (?=.*[!#$%'*+\\/=?^_{}|~-]) -定义的集合中必须有一个符号,后跟0个字符
  • (?=.*[AZ]) - an uppercase ASCII letter is required (?=.*[AZ]) -需要大写ASCII字母
  • (?=.*[az]) - a lowercase ASCII letter is required (?=.*[az]) -需要小写ASCII字母
  • [^.]+(?:\\.[^.]+)* - 1+ chars other than . [^.]+(?:\\.[^.]+)* -除+以外的1个字符. , followed with 0 or more sequences of a . ,后跟0个或多个序列. followed with 1 or more chars other than a dot ( note that we do not have to add \\s into these 2 negated character classes as the first lookahead already prevalidated the whole string, together with its length) 后跟一个或多个除点以外的其他字符( 请注意 ,我们不必在这两个取反的字符类中添加\\s因为第一个前瞻已经预先验证了整个字符串及其长度)
  • $ - end of string. $ -字符串结尾。

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

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