How to validate pasword textbox using these following condition


Password minimum length
 Password
 8
 

Contain at least one alphabetic and one non-alphabetic
 Password
 Yes
 
Non-numeric in first and last position
 Password
 Yes
 
 
Maximum identical consecutive characters
 Password
 2
mcanetvenkatAsked:
Who is Participating?
 
bubbledragonCommented:
<script>
function validate(obj) {
      var passwd = obj["pwd"].value;  // receive the password value

      if (passwd.length < 8) {
            alert("minimum length 8");
            return false;
      }

      if ((passwd.charAt(0).match(/[a-z]/ig) == null) ||
            (passwd.charAt(passwd.length-1).match(/[a-z]/ig) == null)) {
            alert("Non-numeric in first and last position");
            return false;
      }

      AtLeastOneNonAlpha = false;
      for (i=0;i<passwd.length-1;i++)      {
            if (passwd.charAt(i).match(/[a-z]/ig) == null)
                  AtLeastOneNonAlpha = true;

            if (i < (passwd.length+2))
               if ( (passwd.charAt(i) == passwd.charAt(i+1)) &&
                  (passwd.charAt(i+1) == passwd.charAt(i+2)) ) {
                  alert("Maximum identical consecutive characters");
                  return false;
               }
      }

      if (!AtLeastOneNonAlpha) {
            alert("Contain at least one alphabetic and one non-alphabetic");
            return false;
      }

}
</script>
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.