JavaScript下正则表达式密码强度验证
2010-10-20 09:02
666 查看
在用户注册时,为了最大化的协助用户设置安全有效的密码,往往会加一个密码强度验证,下面是一个由正则表达式对密码的验证,返回长度代表密码强度。
intScore =
0
;
if
(
passwd.
match
(/[
a-
z]/))
// [verified] at least one lower case letter
{
intScore = (
intScore+
1
)
}
if
(
passwd.
match
(/[
A-
Z]/))
// [verified] at least one upper case letter
{
intScore = (
intScore+
5
)
}
// NUMBERS
if
(
passwd.
match
(/
/d+/))
// [verified] at least one number
{
intScore = (
intScore+
5
)
}
if
(
passwd.
match
(/(
/d.*
/d.*
/d)/))
// [verified] at least three numbers
{
intScore = (
intScore+
5
)
}
// SPECIAL CHAR
if
(
passwd.
match
(/[!,
@#$%
^&*
?_~]/))
// [verified] at least one special character
{
intScore = (
intScore+
5
)
}
if
(
passwd.
match
(/([!,
@#$%
^&*
?_~].*[!,
@#$%
^&*
?_~])/))
// [verified] at least two special characters
{
intScore = (
intScore+
5
)
}
// COMBOS
if
(
passwd.
match
(/[
a-
z]/) &&
passwd.
match
(/[
A-
Z]/))
// [verified] both upper and lower case
{
intScore = (
intScore+
2
)
}
if
(
passwd.
match
(/
/d/) &&
passwd.
match
(/
/D/))
// [verified] both letters and numbers
{
intScore = (
intScore+
2
)
}
// [Verified] Upper Letters, Lower Letters, numbers and special characters
if
(
passwd.
match
(/[
a-
z]/) &&
passwd.
match
(/[
A-
Z]/) &&
passwd.
match
(/
/d/) &&
passwd.
match
(/[!,
@#$%
^&*
?_~]/))
{
intScore = (
intScore+
2
)
}
return
intScore;
}
-----------------------------------------------------------------------
<tr>
<th nowrap style="HEIGHT: 25px">
新邮箱密码:
</th>
<td noWrap align="left" bgColor="#ffffff">
<input name="txtNewPwd" id="txtNewPwd"
onmouseout="this.className='box1'" onkeyup="pwStrength(this.value)"
maxlength="16" class="newufeild" onmouseover="this.className='box2'"
onblur="showTipMessage(false) " onfocus="showTipMessage(true)"
type="password" size="30" />
<span id="strength_L">弱</span><span
id="strength_M">中</span><span id="strength_H">
强</span>
</td>
</tr>
var getStrength = function ( passwd) {
intScore =
0
;
if
(
passwd.
match
(/[
a-
z]/))
// [verified] at least one lower case letter
{
intScore = (
intScore+
1
)
}
if
(
passwd.
match
(/[
A-
Z]/))
// [verified] at least one upper case letter
{
intScore = (
intScore+
5
)
}
// NUMBERS
if
(
passwd.
match
(/
/d+/))
// [verified] at least one number
{
intScore = (
intScore+
5
)
}
if
(
passwd.
match
(/(
/d.*
/d.*
/d)/))
// [verified] at least three numbers
{
intScore = (
intScore+
5
)
}
// SPECIAL CHAR
if
(
passwd.
match
(/[!,
@#$%
^&*
?_~]/))
// [verified] at least one special character
{
intScore = (
intScore+
5
)
}
if
(
passwd.
match
(/([!,
@#$%
^&*
?_~].*[!,
@#$%
^&*
?_~])/))
// [verified] at least two special characters
{
intScore = (
intScore+
5
)
}
// COMBOS
if
(
passwd.
match
(/[
a-
z]/) &&
passwd.
match
(/[
A-
Z]/))
// [verified] both upper and lower case
{
intScore = (
intScore+
2
)
}
if
(
passwd.
match
(/
/d/) &&
passwd.
match
(/
/D/))
// [verified] both letters and numbers
{
intScore = (
intScore+
2
)
}
// [Verified] Upper Letters, Lower Letters, numbers and special characters
if
(
passwd.
match
(/[
a-
z]/) &&
passwd.
match
(/[
A-
Z]/) &&
passwd.
match
(/
/d/) &&
passwd.
match
(/[!,
@#$%
^&*
?_~]/))
{
intScore = (
intScore+
2
)
}
return
intScore;
}
-----------------------------------------------------------------------
<tr>
<th nowrap style="HEIGHT: 25px">
新邮箱密码:
</th>
<td noWrap align="left" bgColor="#ffffff">
<input name="txtNewPwd" id="txtNewPwd"
onmouseout="this.className='box1'" onkeyup="pwStrength(this.value)"
maxlength="16" class="newufeild" onmouseover="this.className='box2'"
onblur="showTipMessage(false) " onfocus="showTipMessage(true)"
type="password" size="30" />
<span id="strength_L">弱</span><span
id="strength_M">中</span><span id="strength_H">
强</span>
</td>
</tr>
相关文章推荐
- JavaScript下正则表达式密码强度验证
- 利用正则表达式验证密码强度
- 密码强度的正则表达式(JavaScript)总结
- Javascript正则表达式验证密码复杂度
- 手写注册页面,并实现验证信息(AJAX,Jquery,正则表达式,密码强度验证)
- 初学js正则表达式之密码强度验证
- JS正则表达式应用——基于Jquery的验证密码强度特效
- 正则表达式验证密码强度
- 一个正则表达式验证密码强度
- 初学js正则表达式之密码强度验证
- 密码验证,密码强度正则表达式
- 用正则表达式验证密码强度
- 正则表达式验证密码强度
- 密码验证,密码强度正则表达式
- js验证身份证号码的有效方法[1]以及密码验证和强度的验证 1 JS正则表达式 代码 .txt
- 密码验证,密码强度正则表达式
- 一个正则表达式验证密码强度
- 一个正则表达式验证密码强度
- JS基于正则表达式实现的密码强度验证功能示例
- jquery用正则表达式验证密码强度