密码和确认密码验证

时间:2015-02-04 07:21:05

标签: javascript jquery validation passwords

我想验证密码并确认密码字段。已经完成验证密码不匹配。现在我要验证,用户必须输入8到15之间的密码和混合符号,字符,数字

<form id="form" action="" method="post">
<label for="pass">Password</label>
<input type="password" id="pass" class="text" name="your_pass" value="" onblur="passchk()"/>
<label for="c_pass">Confirm Password</label>
<input type="password" id="c_pass" class="text" name="your_c_pass" value="" onblur="confirmPass()"/><br>
<span id="error" style="color:#F00;"> </span>

JS:

function confirmPass() {
    var pass = document.getElementById("pass").value
    var confPass = document.getElementById("c_pass").value
    if(pass != confPass) {
        //alert('Wrong confirm password !');
        document.getElementById('error').innerHTML='wrong confirm password';
    }
    else
    {
        document.getElementById('error').innerHTML='';
    }
}


function passchk(){
    alert('hi');

}

1 个答案:

答案 0 :(得分:0)

8到15个字符,只包含字符,数字,下划线和第一个字符必须是字母

function CheckPassword(input)   
{   
    var pass=  /^[A-Za-z]\w{8,15}$/;  
    if(input.value.match(pass))   
    {     
        return true;  
    }  
        else  
    {   
        alert('Password Is Not Valid')  
        return false;  
    }  
}