Web Analytics Made Easy -
StatCounter Help With Validating Script - CodingForum

Announcement

Collapse
No announcement yet.

Help With Validating Script

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help With Validating Script

    Hi,
    I was wondering if someone can take a look at the code below and help me to get it to work.
    What I'm trying to do is validate a email and password that gets submitted from a form by checking for WHOLE Words instead of just single characters.

    Code:
    <script>
    <!-- Check the from is filled in correctly before submitting -->
    <!-- Hide from older browsers...
    
    //Function to check form is filled in correctly before submitting
    
    var badPass=new Array("Pass","Password")
    var badEmail=new Array("yahoo","aol","msn","hotmail")
    
    function CheckForm () {
    
    	var errorMsg = "";
    	var errorMsgLong = "";
    
    	{
    	var theInfo=document.frmRegister.Password.value;
    	var isGood=false;
    	var curChar;
    	   for (i=0; i<theInfo.length; i++) {
    	       curChar = theInfo.charAt(i);
    	       for (j=0; j<badEmail.length; j++) {
               if (curChar == badEmail[j]) {
                  isGood = true; break;
               }
           }
    	       if (isGood)
    	          break;
       }
    	   if (isGood) {
       }
    	   else {
    	     errorMsg += "\nE-mail Host \t- You E-mail Address Must Be From A Valid Place Of Business\.  Yahoo \, MSN \, Hotmail \, Etc\.\n\t\tIs Not Acceptable\.";
    	   }
    }
    	{
    	var theInfo=document.frmRegister.Password.value;
    	var isGood=false;
    	var curChar;
    	   for (i=0; i<theInfo.length; i++) {
    	       curChar = theInfo.charAt(i);
    	       for (j=0; j<badPass.length; j++) {
               if (curChar == badPass[j]) {
                  isGood = true; break;
               }
           }
    	       if (isGood)
    	          break;
       }
    	   if (isGood) {
       }
    	   else {
    	     errorMsg += "\nPassword \t- You You Must Have A Unique Password\.\n\t\tPass \, Password \, and Common Words Are Not Acceptable\.";
    	   }
    }
    
    	//If there is a problem with the form then display an error
    	if ((errorMsg != "") || (errorMsgLong != "")){
    		msg = "_____________________________________________________________________\n\n";
    		msg += "Your Registration has not been submitted because there are problem(s) with the form.\n";
    		msg += "Please correct the problem(s) and re-submit the form.\n";
    		msg += "_____________________________________________________________________\n\n";
    		msg += "The following field(s) need to be corrected: -\n";
    		
    		errorMsg += alert(msg + errorMsg + "\n" + errorMsgLong);
    		return false;
    
    	}
    }
    // -->
    </script>
    Any help would be great.
    Thanks,
    Larry
    "No Page To Show, Just Likes To Code."

  • #2
    Try this...
    var badPass=new Array("pass","password");
    var badEmail=new Array("yahoo","aol","msn","hotmail") ;

    function CheckForm() {

    var errorMsg = "";
    var errorMsgLong = "";
    var theInfo=document.frmRegister.Password.value;

    if (theInfo.length > 0) {
    for (idx=0;idx < badPass.length;idx++) {
    reg = new RegExp(badPass[idx]);
    if (reg.test(theInfo,"i")) {
    errorMsg +="\nPassword \t- You Must Have A Unique Password.\n\t\tPass, Password, and Common Words Are Not Acceptable.";
    break;
    }
    }
    } else {
    errorMsg += "\nPassword \t- Required";
    }

    theInfo=document.frmRegister.Email.value;
    if (theInfo.length > 0) {
    for (idx=0;idx<badEmail.length;idx++) {
    reg = new RegExp(badEmail[idx]);
    if (reg.test(theInfo,"i")) {
    errorMsg += "\nE-mail Host \t- You E-mail Address Must Be From A Valid Place Of Business. Yahoo, MSN, Hotmail, Etc.\n\t\tare Not Acceptable.";
    break;
    }
    }
    } else {
    errorMsg+= "\nEmail Address \t- Required";
    }

    if ((errorMsg != "") || (errorMsgLong != "")){
    msg = " _____________________________________________________________________\n\n";
    msg += "Your Registration has not been submitted because there are problem(s) with the form.\n";
    msg += "Please correct the problem(s) and re-submit the form.\n";
    msg += " _____________________________________________________________________\n\n";
    msg += "The following field(s) need to be corrected: -\n";
    alert(msg + errorMsg + "\n" + errorMsgLong);
    return false;
    } else {
    return true;
    }
    }

    Comment

    Working...
    X