gpt4 book ai didi

javascript - 匹配Javascript中的特殊字符正则表达式(随机位置)

转载 作者:行者123 更新时间:2023-11-29 21:21:36 26 4
gpt4 key购买 nike

我正在尝试制作一个正则表达式来匹配至少两个特殊字符,用于密码强度检查器。我现在在 Javascript 中有这个:

if (password.match(/([^A-Za-z0-9]{2,})/)) {
//Add strength
}

但这会检查至少有两个特殊字符需要紧接在一起。我怎样才能让它也检查它是否不在彼此之后?

例子:

_aaa!* //Match
a!a_a* //Also match

最佳答案

一种方法:

var password = 'a!a_a*';
var matches = password.match(/([^A-Za-z0-9])/g);

if (matches && matches.length >= 2) {
console.log('Good');
} else {
console.log('Bad');
}

console.log(matches);

关于javascript - 匹配Javascript中的特殊字符正则表达式(随机位置),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38381211/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com