Solved

Javascript, onvalidate question

Posted on 2002-04-24
3
253 Views
Last Modified: 2013-12-24
okay i have the following <cfinput..> line. i need the code for the "passwordcheck" function it calls. i need the function to make sure the password meets the following
requirement:

1. can be numbers or letters
2. at least 8 characters/numbers long
3. no spaces, commas, periods, slashes, or quotes


************************************************
<cfinput type="Password" name="password" size=9 required="Yes" message="Please Choose a Password" onvalidate="passwordcheck">
*************************************************
0
Comment
Question by:sagardeo
3 Comments
 
LVL 15

Accepted Solution

by:
danrosenthal earned 100 total points
Comment Utility
Try this code out....

<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
function passwordcheck(){
     var validchars="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
     if(document.myform.password.value.length<8){return false;}
     for(var i=0;i<document.myform.password.value.length;i++){
          chkstring=document.myform.password.value.substr(i,1);
          if(validchars.indexOf(chkstring) =="-1"){return false;}
     }
     return true;
}
//-->
</SCRIPT>

Be sure to change the form name to match the name of your form (form name in this script is "myform") Otherwise, no other modifications are necessary.
0
 
LVL 19

Expert Comment

by:cheekycj
Comment Utility
you can use Regular Expressions:
function passwordcheck() {
 strng = document.myform.password.value;
 if (strng == "") {
    return false;
 }
    var illegalChars = /[\W_]/; // allow only letters and numbers
    if (strng.length < 8) {
       return false;
    }
    if (illegalChars.test(strng)) {
      return false;
    }
  return true;
}

You can also enforce mixed numbers and characters using regular expressions:

if (!((strng.search(/(a-z)+/))
  && (strng.search(/(A-Z)+/))
  && (strng.search(/(0-9)+/)))) {
  return false;
}

HTH,
CJ
0
 

Author Comment

by:sagardeo
Comment Utility
exactly what i wanted.
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

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 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

10 Experts available now in Live!

Get 1:1 Help Now