Jump to content

Form Validation Script Help


monkeybidz

Recommended Posts

Hello, I have a java form validating script. It will only validate up to 4 vars. In my case up to "var dl_street". 

 

It will not check "var delzipcode" which is next and lets the form submit go through and it will not check anything after that.

 

If I remove anything accosiated to the "var delzipcode" it will check the rest of the vars accordingly.

 

I was wondering if it has to do with Regex for "var pu_zip" and "var delzipcode" being the same.

 

Here is the code:

function validate(form) {
  var paypalid = form.paypalid.value;
  var pu_street = form.pu_street.value;
  var pu_zip = form.pu_zip.value;
  var dl_street = form.dl_street.value;
  var delzipcode = form.delzipcode.value;
  var name = form.name.value;
  var email = form.email.value;
  var message = form.message.value;
  var paypalidRegex = /^[A-Za-z0-9]*$/;
  var pu_streetRegex = /^[A-Za-z0-9 #.]*$/;
  var pu_zipRegex = /^\d{5}(-\d{4})?$/;
  var dl_streetRegex = /^[A-Za-z0-9 #.]*$/;
  var delzipcodeRegex = /^\d{5}(-\d{4})?$/;
  var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
  var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
  var messageRegex = new RegExp(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/gim);

//Checks for PayPal ID///
if(paypalid == "") {
    inlineMsg('paypalid','You must enter your PayPal Transaction Identification Number.',2);
    return false;
  }
  
//Checks for pickup street address//
if(pu_street == "") {
    inlineMsg('pu_street','You must enter the pickup location street address.',2);
    return false;
  }
  if(!pu_street.match(pu_streetRegex)) {
    inlineMsg('pu_street','You have entered an invalid street address character.',2);
    return false;
  }
  
//Checks for pickup zip code//
  if(pu_zip == "") {
    inlineMsg('pu_zip','You must enter the pickup location Zip Code.',2);
    return false;
  }
  if(!pu_zip.match(pu_zipRegex)) {
    inlineMsg('pu_zip','You have entered an invalid US Zip Code.',2);
    return false;
  }

//Checks for delivery street address//
  if(dl_street == "") {
    inlineMsg('dl_street','You must enter the delivery location street address.',2);
    return false;
  }
  if(!dl_street.match(dl_streetRegex)) {
    inlineMsg('dl_street','You have entered an invalid street address character.',2);
    return false;
  }

//Checks for delivery zip code//
   if(delzipcode == "") {
    inlineMsg('delzipcode','You must enter the pickup location Zip Code.',2);
    return false;
  }
  
  if(!delzipcode.match(delzipcodeRegex)) {
    inlineMsg('delzipcode','You have entered an invalid US Zip Code.',2);
    return false;
  }

//Checks for contact name//
  if(name == "") {
    inlineMsg('name','You must enter your name.',2);
    return false;
  }
  if(!name.match(nameRegex)) {
    inlineMsg('name','You have entered an invalid contact name.',2);
    return false;
  }

//Checks for contact email//
  if(email == "") {
    inlineMsg('email','<strong>Error</strong><br />You must enter your email.',2);
    return false;
  }
  if(!email.match(emailRegex)) {
    inlineMsg('email','<strong>Error</strong><br />You have entered an invalid email.',2);
    return false;
  }
  
//Checks for detailed message description//
  if(message == "") {
    inlineMsg('message','You must enter the shipments full detailed description.');
    return false;
  }
  if(message.match(messageRegex)) {
    inlineMsg('message','You have entered an invalid message.');
    return false;
  }
  return true;
}

 

Any help is appreciated!

Link to comment
https://forums.phpfreaks.com/topic/224634-form-validation-script-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.