如何使用js代码判断密码框少于6位字符
<script>
function$(id){returndocument.getElementById(id);}
functiontrim(s){returns.replace(/(^\s*)|(\s*$)/g,"");}
functionLogin(){
varuser=$("user").value;
varpwd=$("pwd").value;
if(!trim(user)){alert("用户名不能为空");$("user").focus();returnfalse;}
if(!trim(pwd)){alert("密码不能为空");$("pwd").focus();returnfalse;}
if(pwd.length<6){alert("密码不能少于6位数");$("pwd").focus();returnfalse;}
if(pwd.length>16){alert("密码不能大于16位数");$("pwd").focus();returnfalse;}
$("loginform").submit();
}
</script>
<formname="loginform"id="loginform">
<inputtype="text"name="user"id="user"/>
<inputtype="password"name="pwd"id="pwd"/>
<inputtype="button"value="提交"onclick="Login();"/>
</form>
扩展资料
判断密码强度是否有数字:
///</summary>
///<paramname="str">密码字符串</param>
functionJugePwdNumeric(sNum)
{
//三、数字:
//0分:没有数字
//10分:1个数字
//20分:大于等于3个数字
varcount=0;
for(vari=0;i<=sNum.length-1;i++)
{
//数字的KEYCODE96-105
if((sNum.charCodeAt(i)>=96)&&(sNum.charCodeAt(0)<=105))
{
count+=1;
}
}
if(count==0)
{
pwdLevel+=0;
}
else
{
hasNumeric=true;
if(count<3)
{
pwdLevel+=10;
}
else
{
pwdLevel+=20;
}
}
}
2013-07-14
推荐于2016-05-30
<script type="text/javascript">
function checkLength(){
var password=document.getElementById("txtpassword"); //获取密码框值
if(password.value.length<6){
alert("密码长度必须大于六位!");
}
}
</script> html代码<body>
<form id="form1" name="form1" method="post" action="">
<label>
<input type="password" name="textfield" id="txtpassword" />
<input type="submit" name="button" id="button" value="提交" onclick="checkLength();"/>
</label>
</form>
</body>