Solved

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

Posted on 2009-04-09
2
1,649 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 250 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

Suggested Solutions

Title # Comments Views Activity
Jquery 2 23
how can i get the string decoded ? 2 28
I want a tab to always be underlined when I open div then change 1 34
Page auto-refreshes when scrolled on iPhone. 5 55
In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
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…
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…

829 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