jQuery.validator.addMethod("lettersonly", function(value, element) { 
return this.optional(element) || /^[a-z\s]*$/i.test(value);
}, jQuery.format("Please enter only letters"));

jQuery.validator.addMethod("zip", function(value, element) {
return this.optional(element) || /^\d{5}$|^\d{5}\-\d{4}$/i.test(value);
}, jQuery.format("Please enter your zip correctly: (e.g. 99999 or 99999-9999)"));

jQuery.validator.addMethod("reg_code", function(value, element) {
return this.optional(element) || /^TexasTech$|^Aggie$|^2013$|^UTMB$|^ETX$|^UTD$|^UTT$|^PO$|^ONE$/i.test(value);
}, jQuery.format("Please enter a valid registration code"));

jQuery.validator.addMethod("passw", function(value, element) {
return this.optional(element) || /^(?=.*[\W])(?=.*[\d])(?=.*[A-Z]).{8,}$/.test(value);
}, jQuery.format("Please enter a valid password"));

var val = $('#everything').validate({
onkeyup: false,
errorClass: "req_mess",
ignore: ":hidden",
rules: {
fname: {
required: true,
minlength: 1,
lettersonly: true
},
lname: {
required: true,
minlength: 1,
lettersonly: true
},
address: {
required: true,
minlength: 1
},
city: {
required: true,
minlength: 1,
lettersonly: true
},
state: {
required: {
depends: function(iitype) {
return $("#state").val() == "";
}
}
},
zip: {
required: true,
minlength: 5,
zip: true
},
phone: {
required: true,
minlength: 10,
phoneUS: true
},
email: {
required: true,
email: true,
remote: { url: "Private/Email_checker.php", async: false }
},
ver_email: {
equalTo: "#email"
},
institution: {
required: true
},
type: {
required: true
},
address_sch: {
required: true
},
prize_name: {
required: "#prize:visible"
},
descr: {
required: "#prize:visible"
},
retail: {
required: "#prize:visible",
digits: true
},
iitype: {
required: {
depends: function(iitype) {
return $("#iitype").val() == "";
}
}
},
type: {
required: {
depends: function(type) {
return $("#type").val() == "";
}
}
},
iitdescr: {
required: "#otherdescr1:visible"
},
typedescr: {
required: "#otherdescr2:visible"
},
city_sch: {
lettersonly: true
},
state_sch: {
lettersonly: true
},
zip_sch: {
zip: true
},
username: {
required: true,
remote: { url: "Private/Available.php", async: false }
},
password: {
required: true,
passw: true
},
password_verify: {
required: true,
equalTo: "#password"
},
regis_code: {
required: true,
reg_code: true,
remote: {
url: "Private/Code_checker.php",
data: {
code: function() {
return $("#regis_code").val();
}
},
async: false
}
}
},
messages: {
fname: {
required: "Please enter your first name",
lettersonly: "Please only use letters"
},
lname: {
required: "Please enter your last name",
lettersonly: "Please only use letters"
},
address: {
required: "Please enter your permanent address"
},
city: {
required: "Please enter your city",
lettersonly: "Please only use letters"
},
state: {
required: "Please choose a state from the drop down list"
},
zip: {
required: "Please enter your zip",
minlength: "Please enter in your 5 or 9 digit zip code",
zip: "Please enter your zip correctly: (e.g. 99999 or 99999-9999)"
},
phone: {
required: "Please enter your phone number",
phoneUS: "Please enter a valid phone number: (e.g. 19999999999 or 9999999999)"
},
email: {
required: "Please enter your email address",
email: "Please enter a valid email address: (e.g. [email protected])",
remote: "That email address is already registered"
},
ver_email: {
equalTo: "Your email addresses do not match"
},
institution: {
required: "Please enter the name of your institution"
},
type: {
required: "Please select your the appropriate type for your institution"
},
address_sch: {
required: "Please enter the address of your institution"
},
prize_name: {
required: "Please enter the name of your prize"
},
descr: {
required: "Please enter in a description of your prize"
},
retail: {
required: "Please enter in the retail value of your prize",
digits: "Please only use numbers"
},
iitdescr: {
required: "Please provide a brief descrition of the institution"
},
typedescr: {
required: "Please provide a brief description of the type"
},
iitype: {
required: "Please select an option from the list, if none are appropriate please select 'Other'"
},
type: {
required: "Please select an option from the list, if none are appropriate please select 'Other'"
},
username: {
required: "Please enter an username",
remote: "Username is already taken"
},
password: {
required: "Please enter a password that is a minimum of 8 characters and containers 1 upper case, 1 symbol, and 1 number"
},
password_verify: {
required: "Please reenter your password to verify",
equalTo: "Your passwords did not match"
},
regis_code: {
required: "Please enter a registration code",
remote: "That registration code limit has been reached. If you do not know any other code, please restart the registration process and select a different option or contact your STEM center directly."
},
"workshop" : "Please select an option"
},
errorPlacement: function (error, element) {
if (element.is("input:radio")) {
element.parents("div:first").before(error);
} else {
element.after(error);
}
}
});