Sunday, 8 April 2012

Javascript : Password Validation with Regular expression.

Hi viewers,


This topic- Password Validation with Regular expression.


Its a daily process for web developers to validating the password with certain rules.With java script client side validate can be achieved. Below the code will help you to validate the password which contain at least one Letter , one Number & one special character. The password length must be within a given range.

Password Validation with Regular expression.


/* Password must be at least one char, one special char & one digit & the length must be given*/
function validatePassword(pwdelem,alertmsg){
    var password_expression=/^((?=.*[a-zA-Z])(?=.*\d)(?=.*[#@%$]).{6,20})$/;
    if(pwdelem.value.match(password_expression)){
        return true;
    }
    else{
        alert(alertmsg);
        pwdelem.focus(); //Set focus to the given source element id ( textbox or password) ,it is optional .
        return false;
    }
}





thanks,

Any help ,ping me.
manojbardhan64@gmail.com
manonbardhan2009.blogspot.com