/*****Custom validation rules for jQuery form validation*****/

// Valid us phone number
jQuery.validator.addMethod("phoneUS", function(phone_number, element) {
    phone_number = phone_number.replace(/\s+/g, ""); 
	return this.optional(element) || phone_number.length > 9 &&
		phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
}, "Invalid phone number.");

// Extended Valid us phone number.  Allows 20 digits. xxx-xxx-xxxx(10 -'s or digits)
jQuery.validator.addMethod("ExtendedphoneUS", function(phone_number, element) {
    phone_number = phone_number.replace(/\s+/g, ""); 
	return this.optional(element) || phone_number.length > 9 &&
		phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}(\d|-){0,10}$/);
}, "Invalid phone number.");

// Valid last four SSN: 0001-9999
jQuery.validator.addMethod("last4Social", function(social, element) {
    social = social.replace(/\s+/g, ""); 
	return !social.match(/^0000$/) && social.match(/^[0-9]{4}$/);
}, "Please enter a valid last 4 SSN.");

// Valid military email. (ending in .mil) - This should be coupled with the regular email validator
jQuery.validator.addMethod("militaryEmail", function(milEmail, element) {     
	return /.mil$/.test(milEmail);
}, "Please enter a valid military email address.");
