monkeybidz Posted January 16, 2011 Share Posted January 16, 2011 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! Quote Link to comment https://forums.phpfreaks.com/topic/224634-form-validation-script-help/ Share on other sites More sharing options...
monkeybidz Posted January 16, 2011 Author Share Posted January 16, 2011 Basically, the form stops validating after "var delzipcode". Quote Link to comment https://forums.phpfreaks.com/topic/224634-form-validation-script-help/#findComment-1160356 Share on other sites More sharing options...
brianlange Posted January 16, 2011 Share Posted January 16, 2011 hard to tell exactly without seeing the html. Can you post this or post a url? I would use delzipcodeRegex.test(delzipcode) since you only need a true or false value returned. Having the same regex two fields shouldn't be a problem. Quote Link to comment https://forums.phpfreaks.com/topic/224634-form-validation-script-help/#findComment-1160377 Share on other sites More sharing options...
monkeybidz Posted January 17, 2011 Author Share Posted January 17, 2011 I am glad you mentioned HTML. I was wondering what that had to do with anything. Seems the form field input name "delzipcode" did not match the ID. Works perfect now. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/224634-form-validation-script-help/#findComment-1160563 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.