Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Javascript, onvalidate question

Posted on 2002-04-24
3
Medium Priority
?
279 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

Simplify Your Workload with One Tool

How do you combat today’s intelligent hacker while managing multiple domains and platforms? By simplifying your workload with one tool. With Lunarpages hosting through Plesk Onyx, you can:

Automate SSL generation and installation with two clicks
Experience total server control

Question has a verified solution.

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

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

604 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