Solved

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

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

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 …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

809 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