我使用http://mootools.net作为JS表单验证脚本。我想检查用户选择的密码是否包含以下四个标准中的两个:
minimum 1 digit
minimum 1 small letter
minimum 1 capital letter
minimum 1 special character (!@#$%^*-_+=.)
至少6到50位数。
使用此扩展程序可以正常运行:
uppercase: /(?=^.{6,50}$)((?=.*\d)|([!,%,&,@,#,$,^,*,?,_,~]))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$/
检查用户密码是否符合所有四个条件。现在我想以这种方式更改脚本,如果密码只符合两个,则接受密码。知道如何更改脚本吗?
答案 0 :(得分:1)
你可以使用我多年前写的这个插件:
https://github.com/DimitarChristoff/StrongPass
它允许您拆分支票并分配相对分数和总体及格分数,这个想法是并非所有支票都同样强大。此外,分数越长越长。
checks: [
/* alphaLower */ {
re: /[a-z]/,
score: 1
},
/* alphaUpper */ {
re: /[A-Z]/,
score: 5
},
/* mixture of upper and lowercase */ {
re: /([a-z].*[A-Z])|([A-Z].*[a-z])/,
score: 2
},
/* threeNumbers */ {
re: /(.*[0-9].*[0-9].*[0-9])/,
score: 7
},
/* special chars */ {
re: /.[!@#$%^&*?_~]/,
score: 5
},
/* multiple special chars */ {
re: /(.*[!@#$%^&*?_~].*[!@#$%^&*?_~])/,
score: 7
},
/* all together now, does it look nice? */ {
re: /([a-zA-Z0-9].*[!@#$%^&*?_~])|([!@#$%^&*?_~].*[a-zA-Z0-9])/,
score: 3
},
/* password of a single char sucks */ {
re: /(.)\1+$/,
score: 2
}
],
所以你可以分解你的正则表达式并在这里添加或查看源代码并获得一些想法。