?
Solved

Javascript, onvalidate question

Posted on 2002-04-24
3
Medium Priority
?
278 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:Judy Deo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 15

Accepted Solution

by:
danrosenthal earned 400 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:Judy Deo
ID: 6969104
exactly what i wanted.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

752 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