Solved

Javascript, onvalidate question

Posted on 2002-04-24
3
269 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
ID: 6967277
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
ID: 6968867
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
ID: 6969104
exactly what i wanted.
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

791 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