简体   繁体   English

需要此正则表达式不需要至少1个大写字母

[英]Need this regular expression not to require at least 1 capital letter

The regular expression below is written now to require a capital letter. 现在编写下面的正则表达式以要求使用大写字母。 I was just told that capital letters are optional but not required. 有人告诉我,大写字母是可选的,但不是必需的。 How can I write this regular expression without changing any of the other parameters to not make at least one capital letter required. 如何在不更改任何其他参数的情况下编写此正则表达式,以使至少不需要一个大写字母。

/^(?:(?!([a-zA-Z0-9-().&@?""#,+''\s\/])\1\1)[a-zA-Z0-9-().&@?""#,+''\s\/]){7,}$/

That regular expression already does not require an upper-case character. 该正则表达式已经不需要大写字符了。 The only "interesting" things it insists on are that the string cannot start with the same thing repeated 3 times (the same character that is), and the overall string needs to be at least seven characters long. 它坚持的唯一“有趣”的事情是字符串不能以相同的事物重复3次(即相同的字符)开头,并且整个字符串至少需要七个字符长。

Also the doubling of single- and double-quote characters in the regex is not necessary. 同样,不需要在正则表达式中将单引号和双引号字符加倍。

There is nothing in that regex that requires uppercase letters. 该正则表达式中没有要求大写字母的内容。 The requirements imposed by that regex are: 该正则表达式施加的要求是:

  • At least 7 characters long. 至少7个字符长。
  • Contains only uppercase and lowercase letters, digits 0-9, the symbols -().&@?"#,+' , whitespace, or / . 仅包含大写和小写字母,数字0-9,符号-().&@?"#,+' ,空格或/
  • Does not start with 3 of the same character in a row. 不能以连续3个相同字符开头。 (The author probably intended this check to apply to the entire password, but it does not.) (作者可能希望此检查适用于整个密码,但并非如此。)

If I'm not mistaken this appears to be used for password validation. 如果我没记错的话,这似乎用于密码验证。 This is a poor use of regexes for several reasons. 由于多种原因,这是对正则表达式的不良使用。

  1. It's hard to read. 很难读。 What does the regex check, exactly? 正则表达式究竟检查什么? What does that big mess of characters actually do? 这么大的字符混乱实际上是做什么的? If you're not a regex expert it's gibberish. 如果您不是正则表达式专家,那简直就是胡言乱语。

  2. It's got several requirements crammed into one big regex. 一个大的正则表达式中塞满了几个要求。 It would be easier to read and more maintainable if the checks were split into several lines of code: 如果将检查分成几行代码,将更易于阅读和维护。

     if (password.length < 7) reject("Too short."); if (numRepeatedCharacters(password) >= 3) reject("Too repetitive."); if (numDigits(password) < 1) reject("Digit required."); if (numSymbols(password) < 1) reject("Symbol required."); // etc. 
  3. It contains a character whitelist instead of a blacklist. 它包含一个字符白名单而不是黑名单。 Please don't whitelist characters. 请不要将字符列入白名单。 There's no reason to prevent users from using characters you haven't thought of. 没有理由阻止用户使用您从未想到的字符。 What if they want to use an asterisk, percent sign, accented letters, etc.? 如果他们想使用星号,百分号,带重音的字母等怎么办? You will reject those characters for no good security reason. 您将出于安全原因拒绝这些字符。

暂无
暂无

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

相关问题 Javascript正则表达式,表示“至少X个字符,带有大写字母和数字” - Javascript regular expression for “at least X characters, have a capital letter and a number” 正则表达式至少匹配一个大写字母和至少一个数字和任意数量的特殊字符 - Regular expression to match at least One capital letter and at least One digit and any number of special charecter 需要 4-12 个字母数字字符或特殊字符 (~!@$%&amp;*_+) 至少一个字母的正则表达式,不能有空格 - Need regular expression for 4-12 alphanumeric characters or special characters (~!@$%&*_+) at least one letter, no spaces 正则表达式以匹配九个数字和最后一个大写字母 - Regular expression to match nine numbers and a capital letter at the end JavaScript - 检查字符串的大写和小写字母的正则表达式 - JavaScript - regular expression to check string for capital and lower case letter 正则表达式,至少10个字符,包括1个数字和1个大写字母 - Regular expression for minimum of 10 characters and include 1 numeral and one capital letter 正则表达式强制在字符串中至少包含一个字母和数字? - regular expression to force to have at least one letter and number in a string? 正则表达式:允许字母,数字和空格(至少有一个字母不是数字) - Regular Expression: Allow letters, numbers, and spaces (with at least one letter not number) 正则表达式:允许字母,数字和空格(至少包含一个字母或数字) - Regular Expression: Allow letters, numbers, and spaces (with at least one letter or number) 正则表达式使每个单词的首字母大写,包括特殊字符 - Regular Expression to make first letter of each word capital including special characters
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM