【问题标题】:Regex: Password validation of php正则表达式:php的密码验证
【发布时间】:2012-06-01 11:47:37
【问题描述】:

我正在对我的新项目进行一些密码验证。我有这个规则,我想使用 php preg_match() 函数在正则表达式模式上进行转换:

  • 接受所有字符。
  • 空格除外。
  • 最少 4 个字符。
  • 最多 20 个字符。

提前谢谢你!

【问题讨论】:

标签: php regex


【解决方案1】:

试试这个

(?s)^(\S{4,20})$

说明

"(?s)" +     // Match the remainder of the regex with the options: dot matches newline (s)
"^" +        // Assert position at the beginning of the string
"(" +        // Match the regular expression below and capture its match into backreference number 1
   "\\S" +       // Match a single character that is a “non-whitespace character”
      "{4,20}" +      // Between 4 and 20 times, as many times as possible, giving back as needed (greedy)
")" +
"$"          // Assert position at the end of the string (or before the line break at the end of the string, if any)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-06
    • 2016-10-19
    • 2011-03-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多