Breaking

Password validation with min 6 chars, at least one letter and one number and may contain special characters

Another java script problem we are going to explain ' Password validation with min 6 chars, at least one letter and one number and may contain special character' .Below example simply add validation when you submit any sign up or other form using javascript .







For this we need to  get  val of password that user type in input box.i.e >  




<input type="password" id ="lock" />


vaildPassword = function () {
   var passVal = document.getElementById('lock').value;
   if (passVal.length < 6) {
       alert("Password is too short");
       return ("Password is too short");
   } else if (passVal.length > 30) {
       alert("Password is too long");
       return ("Password is too long");
   } else if (passVal.search(/\d/) == -1) {
       alert("Plz enter at least one number");
       return ("Plz enter at least one number");
   } else if (passVal.search(/[a-zA-Z]/) == -1) {
       alert("Plz enter at least one letter");
       return ("Plz enter at least one letter");
   } else if (passVal.search(/[^a-zA-Z0-9\!\@\#\$\%\^\&\*\(\)\_\+\.\,\;\:]/) != -1) {
       alert("Some char are not allowed.");
       return ("Some char are not allowed.");
   }
   alert("Great Password!!");
   return ("success");

}

No comments:

Powered by Blogger.