jQuery Error

I'm getting an error in my jQuery that I don't understand.
SyntaxError: expected expression, got ','

It says it is on line number: 29 of this code

<script>
jQuery.validator.addMethod("regex", function (value, element, regexp) {
				var re = new RegExp(regexp);
				return this.optional(element) || re.test(value);
			},
			"Please check your input.");

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

$().ready(function(){
		$("#mail_info").validate({ rules: {
				"item_options[association_membership]": {
					required:true	
				},
				"item_options[purchase_price]": {
					digits:true
				},
				"item_options[accessories_value]": {
					digits:true,
					max:5000
				},
				"item_options[contact_email]": {
					regex:true
				},
				"item_options[type_bicycle]": {
					required: true
				},
				"item_options[bicycle_material]": {
					required:true
				},
				"item_options[usage]": {
					required: true
				},
				"item_options[serial_number]": {
					serialnumber: "/^[a-z0-9]+$/i"
				}				
			},

			messages: {
				"item_options[association_membership]": {
					required: "Indicate A Membership"	
				},
				"item_options[purchase_price]": {
					digits: "Numeric value allowed"
				},
				
				"item_options[accessories_value]": {
					digits: "Only a numeric value allowed",
					max: "You can not have over $5000 in accessories"
				},
				"item_options[contact_email]": {
					email: "Please enter a valid email address",
					regex: "Incorrect format"
				},
				"item_options[type_bicycle]": {
					required: "Required"
				},
				"item_options[bicycle_material]": {
					required: "Required"
				},
				"item_options[usage]": {
					required: "Required"
				},
				"item_options[serial_number]": {
					serialnumber: "Alpha Numeric Only"
				}
			},
			errorElement: "div"
		});
			
	});

Open in new window

LVL 7
rgranlundAsked:
Who is Participating?
 
Rainer JeschorCommented:
Hi,
you have to provide a regular expresion when using the regex rule as this rule is parameter driven eg:
"item_options[contact_email]": {
					regex: /^(([^<>()[]\.,;:s@"]+(.[^<>()[]\.,;:s@"]+)*)|(".+"))@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}])|(([a-zA-Z-0-9]+.)+[a-zA-Z]{2,}))$/igm
				},

Open in new window


HTH
Rainer
0
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.

All Courses

From novice to tech pro — start learning today.