jQuery Form Validation

I realized something about my jQuery Form validation.  I am using validatejs.js.

I have a form that validates about 20 fields.  Half of the fields are Select and the rest are input.  When I click submit all of the valitaion error warnings show.  As I correct the warnings and click submit again, the form does not submit and the remain Validation Errors still show. BUT once I finsh selecting all of the Select option and I leave the inputs blank, even though they show the validation error, If all of the Select options are chosen, the form submits anyway without all of the required options being filled in.

Make sense?
Here is the entire code:
$(document).ready(function() {
	jQuery.validator.addMethod("regex", function (value, element, regexp) {
				var re = new RegExp(regexp);
				return this.optional(element) || re.test(value);
			},
			"Incorrect format; Please check your input.");

jQuery.validator.addMethod("phone", function (value, element, params) {
				var pho = new RegExp(regex);
				return this.optional(element) || pho.test(value);
			},
			"Incorrect Format"	);

jQuery.validator.addMethod("serialnumber", function (value, element, params) {
	var serial = new RegExp(params);
	return this.optional(element) || serial.test(value);
},
"Incorrect Format");
	var validateCart = function() {
		$("#update_cart_form").validate({ rules: {
				"item_options[0][first_name]": {
					required:true	
				},
				"item_options[0][last_name]": {
					required:true
				},
				"item_options[0][association_membership]": {
					required:true	
				},
				"item_options[0][gender]": {
					required:true	
				},
				"item_options[0][purchase_price]": {
					required:true,
					digits:true
				},
				"item_options[0][accessories_value]": {
					digits:true,
					max:5000
				},
				"item_options[0][contact_email]": {
					required: true,
					email:true,
					regex:"^((\"[\\w\\s-]+\")|([\\w-]+(?:\\.[\\w-]+)*)|(\"[\\w\\s-]+\")([\\w-]+(?:\\.[\\w-]+)*))(@((?:[\\w-]+\\.)*\\w[\\w-]{0,66})\\.([a-zA-Z]{2,6}(?:\\.[a-zA-Z]{2})?)$)|(@\\[?((25[0-5]\\.|2[0-4][0-9]\\.|1[0-9]{2}\\.|[0-9]{1,2}\\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\\]?$)"
				},
				"item_options[0][professional_cyclist]": {
					required: true
				},
				"item_options[0][triathlete]": {
					required: true
				},
				"item_options[0][type_bicycle]": {
					required: true
				},
				"item_options[0][year_built]": {
					required: true
				},
				"item_options[0][model]": {
					required: true
				},
				"item_options[0][bicycle_material]": {
					required: true
				},
				"item_options[0][usage]": {
					required: true
				},
				"item_options[0][marital_status]": {
					required: true
				},
				"item_options[0][purchase_date]": {
					required: true
				},
				"item_options[0][purchase_price]": {
					required: true
				},
				"item_options[0][usage]": {
					required: true
				},
				"item_options[0][used]": {
					required: true
				},
				"item_options[0][insured_first_name]": {
					required: true
				},
				"item_options[0][insured_last_name]": {
					required: true
				},
				"item_options[0][bicycle_location]": {
					required: true
				},
				"item_options[0][location_address]": {
					required: true
				},
				"item_options[0][location_city]": {
					required: true
				},
				"item_options[0][location_state]": {
					required: true
				},
				"item_options[0][location_zip]": {
					required: true
				},
				"item_options[0][location_phone]": {
					required: true,
					phone: "(^\d+(-\d+)*$)"
				},
				"item_options[0][minors]": {
					required: true
				},
				"item_options[0][manufacturer]": {
					required: true
				},
				"item_options[0][serial_number]": {
					required: true,
					serialnumber: "(^[a-zA-Z0-9]+$)"
				}
			},

			messages: {
				"item_options[0][first_name]": {
					required: "Required"
				},
				"item_options[0][last_name]": {
					required: "Required"
				},
				"item_options[0][association_membership]": {
					required: "Required"	
				},
				"item_options[0][gender]": {
					required: "Required"	
				},
				"item_options[0][marital_status]": {
					required: "Required"	
				},
				"item_options[0][purchase_price]": {
					required: "Required",
					digits: "Only a numeric value allowed"
				},				
				"item_options[0][accessories_value]": {
					digits: "Only a numeric value allowed",
					max: "Over $5000 in accessories not allowed"
				},
				"item_options[0][contact_email]": {
					required: "Required", 
					email: "Please enter a valid email",
					regex: "Incorrect format"
				},
				"item_options[0][professional_cyclist]": {
					required: "Required"
				},
				"item_options[0][triathlete]": {
					required: "Required"
				},
				"item_options[0][type_bicycle]": {
					required: "Required"
				},
				"item_options[0][year_built]": {
					required: "Required"
				},
				"item_options[0][model]": {
					required: "Required"
				},
				"item_options[0][bicycle_material]": {
					required: "Required"
				},
				"item_options[0][used]": {
					required: "Required"
				},
				"item_options[0][usage]": {
					required: "Required"
				},				
				"item_options[0][purchase_date]": {
					required: "Required"
				},
				"item_options[0][purchase_price]": {
					required: "Required"
				},
				"item_options[0][used]": {
					required: "Required"
				},
				"item_options[0][insured_first_name]": {
					required: "Required"
				},
				"item_options[0][insured_last_name]": {
					required: "Required"
				},
				"item_options[0][bicycle_location]": {
					required: "Required"
				},
				"item_options[0][location_address]": {
					required: "Required"
				},
				"item_options[0][location_city]": {
					required: "Required"
				},
				"item_options[0][location_zip]": {
					required: "Required"
				},
				"item_options[0][location_phone]": {
					required: "Required",
					phone: "Incorrect Format"
				},
				"item_options[0][minors]": {
					required: "Required"
				},
				"item_options[0][manufacturer]": {
					required: "Required"
				},
				"item_options[0][serial_number]": {
					required: "Required",
					serialnumber: "Alpha Numeric only"
				}
			},
			errorElement: "div"
		});	
	};

$(".submit_to_cart").on("click", validateCart);
}); //  END Document Ready

Open in new window

LVL 7
rgranlundAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rainer JeschorCommented:
Hi,
can you please confirm that you use the validation plugin from
http://jqueryvalidation.org/
?
Because ValidateJS (http://validatejs.org/) has a completely different syntax.

I built a sample and in IE this works:
http://jsfiddle.net/EE_RainerJ/qzes1coj/
Do you have a link to your page? Perhaps the issue is somewhere else?
Thanks.
Rainer
0
rgranlundAuthor Commented:
You can go here and fill out the highlighted fields and submit.  On the following page click Purchase:
http://23.101.151.179/index.php/store/29

Yes, I am using  * http://jqueryvalidation.org/
0
rgranlundAuthor Commented:
I am getting the error       

ReferenceError: regex is not defined
var pho = new RegExp(regex);
0
Rainer JeschorCommented:
Hi,
sorry I just copied your sample code as base.
Please rename in the addMethod phone the parameter params to regex.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.