Solved

Javascript, onvalidate question

Posted on 2002-04-24
3
267 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

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…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

831 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