• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 279
  • Last Modified:

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
0
mcanetvenkat
Asked:
mcanetvenkat
1 Solution
 
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now