Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Check password has at least 1 uppercase, 1 lowercase , 1 number and 8 characters minimum

Posted on 2009-04-09
2
Medium Priority
?
1,694 Views
Last Modified: 2012-05-06
Hi,

I'm just trying to validate a password field.
Can someone please help with an expression to validate that the field has:
1 uppercase, 1 lowercase , 1 number and 8 characters minimum

Thanks.
0
Comment
Question by:mrduckers
  • 2
2 Comments
 
LVL 9

Accepted Solution

by:
Sreedhar Vengala earned 1000 total points
ID: 24112740
something on these grounds:
<HTML>
<HEAD>

<script Language="JavaScript">

function checkPassword () {

      var strng  = document.passwordResetForm.newpass.value;
      var strng2 = document.passwordResetForm.verifypass.value;
      var errMsg = "";
      if (strng == "") {
            errMsg = "Enter a password.\n";
      }

      if ((strng.length < 6) || (strng.length > 16)) {
            errMsg += "The password is the wrong length\n";
      }
      if (/[^a-zA-Z0-9]/.test(strng)) {
            errMsg += "The password contains illegal characters.\n";
      }

      if (!/[0-9]/.test(strng) || !/[a-zA-Z]/.test(strng)) {
            errMsg += "The password must contain at least one letter and one numeral.\n";
      }

      if(strng!=strng2)
            errMsg += "Your passwords do not match!\n";
     
      if(errMsg==''){
            return true;
      } else {
            alert(errMsg);
            return false;
      }
return false;

}
</script>

    <title>Password Reset</title>

</HEAD>

<body>

<FORM NAME="passwordResetForm" ACTION=" " METHOD=post onsubmit="return checkPassword()">


           Enter New Password: <input type=text name=newpass value=""><br>
               Verify Password: <input type=text name=verifypass value=""><br><br>

             <input type=submit value="Reset Password"><br><br><br>

</FORM>
</BODY>
</HTML>
0
 
LVL 9

Expert Comment

by:Sreedhar Vengala
ID: 24112751
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question