Solved

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

Posted on 2009-04-09
2
1,638 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now