如何使用js代码判断密码框少于6位字符

JavaScript017

如何使用js代码判断密码框少于6位字符,第1张

<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=0i<=sNum.length-1i++)

{

//数字的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

}

}

}

onclick时 执行一段js 简单判断以用户名是否为空 如下:<a onclick="return issubit()"><script>function issubit(){ if(document.getElementById("username").value=="") { alert("用户名不可以为空!")//提示 document.getElementById("username").focus()//焦点 return false//返回false} else {return ture }}</script>