Regex 用于测试字符串中是否有两个以上数字的正则表达式

Regex 用于测试字符串中是否有两个以上数字的正则表达式,regex,password-protection,Regex,Password Protection,据我所知,\d{2,}匹配2个或更多连续数字,但我需要知道字符串中是否有任何2个数字 我也会很感激一些好的链接到密码强度米 我现在用的是 function passwordStrengthPercent(pwd,username) { var score = 0, special = /(.*[!,@,#,$,%,^,&,*,?,_,~,;,:,`,|,\\,\/,<,>,\{,\},\[,\],=,\+])/ if (pwd.length < 8 )

据我所知,
\d{2,}
匹配2个或更多连续数字,但我需要知道字符串中是否有任何2个数字

我也会很感激一些好的链接到密码强度米

我现在用的是

function passwordStrengthPercent(pwd,username)
{
    var score = 0, special = /(.*[!,@,#,$,%,^,&,*,?,_,~,;,:,`,|,\\,\/,<,>,\{,\},\[,\],=,\+])/
    if (pwd.length < 8 ) return 0
    if (pwd.toLowerCase() == username.toLowerCase()) return -1
    score += pwd.length * 4
    score += ( checkRepetition(1,pwd).length - pwd.length )
    score += ( checkRepetition(2,pwd).length - pwd.length )
    score += ( checkRepetition(3,pwd).length - pwd.length )
    score += ( checkRepetition(4,pwd).length - pwd.length )
    if (pwd.match(/(.*[e].*[e].*[e])/))  score -= 15//most common letter in passswords?
    if (pwd.match(/(.*[a].*[a].*[a])/))  score -= 15//most common letter in passswords?
    if (pwd.match(/(.*[o].*[o].*[o])/))  score -= 10//most common letter in passswords?
    if (pwd.match(/^\l+$/) || pwd.match(/^\d+$/) )  return score/2//there was w here in regexp
    if (pwd.match(/(.*[0-9].*[0-9].*[0-9])/))  score += 10

    //todo additional rules 11
    if (pwd.match(special)) score += 15
    if (pwd.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/))  score += 15
    if (pwd.match(/(w)/) && pwd.match(/(d)/))  score += 15
    if (pwd.match(special) && pwd.match(/(d)/))  score += 10
    if (pwd.match(special) && pwd.match(/(w)/))  score += 10
    if ( score < 0 ) return 0
    if ( score > 100 ) return 100
  return score
}
函数密码强度百分比(pwd,用户名)
{
变量得分=0,特殊=/(.[!,@,#,$,%,^,&,*,?,,,,,:,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+)/
如果(pwd.length<8)返回0
if(pwd.toLowerCase()==username.toLowerCase())返回-1
分数+=pwd.length*4
分数+=(检查重复(1,pwd).length-pwd.length)
分数+=(检查重复(2,pwd).length-pwd.length)
分数+=(检查重复(3,pwd).length-pwd.length)
分数+=(检查重复(4,pwd).length-pwd.length)
如果(pwd.match(/(.[e].[e].[e])/)得分-=15//密码中最常见的字母?
如果(pwd.match(/(.[a].[a].[a])/)得分-=15//密码中最常见的字母是什么?
如果(pwd.match(/(.[o].[o].[o])/)得分-=10//密码中最常见的字母是什么?
if(pwd.match(/^\l+$/)| | pwd.match(/^\d+$/)返回分数/2//regexp中有w
如果(pwd.match(/(.[0-9].[0-9].[0-9])/)得分+=10
//todo附加规则11
如果(pwd.匹配(特殊))分数+=15
如果(pwd.match(/([a-z].[a-z])|([a-z].[a-z])/)得分+=15
如果(pwd.match(/(w)/)和&pwd.match(/(d)/)得分+=15
如果(特殊)和匹配(/(d)/)得分+=10
如果(特殊)和匹配(/(w)/)得分+=10
如果(分数<0)返回0
如果(分数>100)返回100
回击得分
}
您可以试试

^.*\d.*\d.*$
仅当包含(至少)两位数字时才匹配。

您可以使用:

\d.*\d

匹配行中任意位置的两个数字,即使它们之间有其他字符。

检查是否有两个数字:

^[^\d]*\d[^\d]*\d[^\d]*$
请参阅grep测试:

kent$  echo "23
2   3
ax3x2x
aaaaa23
a222
2
3x3x4
3 4 5"|grep -P "^[^\d]*\d[^\d]*\d[^\d]*$"                                                                                                
23
2   3
ax3x2x
aaaaa23

这是一个米-
d
匹配一个文字字母d。你想要的是
\d
。这是另一个量表:但既然他至少需要两个,他就必须检查一个和两个?你不需要
^.*
*$
部分。+1或更好:
/\d\d*\d/
(万能的点很少是必要的,或者是最有效的选择—“说你的意思,说你的意思!”)