Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.