/** * This file is intended to keep all the custom rules (methods) and profiles created for the jQuery validation plugin * * Author - Mohammad Nadeem */ /***** Rules (Methods) ******/ // White lists jQuery.validator.addMethod("nameRule", function(value, element) { return this.optional(element) || /^[a-z0-9',\.\-/&\s]+$/i.test(value); }, "Please provide valid name."); jQuery.validator.addMethod("addressRule", function(value, element) { return this.optional(element) || /^[a-z0-9',\.\-/&#@\s]+$/i.test(value); }, "Please provide valid address."); jQuery.validator.addMethod("inputRule", function(value, element) { return this.optional(element) || /^[a-z0-9',\.\-/&#@_"\$\+\[\]\(\):;^\|\s]+$/i.test(value); }, "Please provide valid value."); jQuery.validator.addMethod("cityRule", function(value, element) { return this.optional(element) || /^[a-z0-9',\.\-\s]+$/i.test(value); }, "Please provide valid city name."); jQuery.validator.addMethod("phoneRule", function(value, element) { return this.optional(element) || /^[0-9-\(\)\s]+$/i.test(value); }, "Please provide valid phone number."); jQuery.validator.addMethod("splcharRule", function(value, element) { return this.optional(element) || /^[a-zA-Z0-9 @+%\\/''!#$^?:.,\n(){}~_-]+$/i.test(value); }, "Please provide valid input"); jQuery.validator.addMethod("spaceRule", function(value, element) { return this.optional(element) || ! / {2,}/g.test(value); }, "Please remove all double spaces within the text fields."); /* ComemntRule is same as splcharRule except it allows semi-colon */ jQuery.validator.addMethod("commentRule", function(value, element) { return this.optional(element) || /^[a-zA-Z0-9 @+%\\/''!#$^?,:;.\n(){}~_-]+$/i.test(value); }, "Please provide valid inputs. Allowed characters:
a-z A-Z 0-9 @+%\\/ ' ! # $ ^ ? , : ; . (){} ~_-"); /* ComemntRule is same as splcharRule except it allows semi-colon */ jQuery.validator.addMethod("noLineBreakCommentRule", function(value, element) { return this.optional(element) || /^[a-zA-Z0-9 @+%\\/''!#$^?,:;.\n(){}~_-]+$/i.test(value); }, "Please provide valid inputs. Allowed characters:a-z A-Z 0-9 @+%\\/'! # $ ^ ? , : ; . (){} ~_-"); /* commentValidationWithDoubleQuotesRule is same as noLineBreakCommentRule except it allows double quotes */ jQuery.validator.addMethod("commentValidationWithDoubleQuotesRule", function(value, element) { return this.optional(element) || /^[a-zA-Z0-9 @+%\\/''!#$^?,:;".\n\r(){}~_-]+$/i.test(value); }, "Please provide valid inputs. Allowed characters:a-z A-Z 0-9 @+%\\/ ' ! # $ ^ ? , \" : ; . (){} ~_-"); jQuery.validator.addMethod("alphaNumericRule", function(value, element) { return this.optional(element) || /^[a-zA-Z0-9]*$/i.test(value); }, "Please provide valid input"); jQuery.validator.addMethod("alphaNumericRuleWithEmail", function(value, element) { return this.optional(element) || /^[a-zA-Z0-9]*$/i.test(value) || /^([a-zA-Z0-9._'-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,3})+$/i.test(value); }, "Please provide valid input"); /**Validation to trim the search string in EIN field in Search Applicant*/ jQuery.validator.addMethod("alphaNumericRuleForSearchApplicant", function(value, element) { return this.optional(element) || /^[a-zA-Z0-9]*$/i.test(trimValue(value)); }, "Please provide valid input"); jQuery.validator.addMethod("emailRule", function(value, element) { return this.optional(element) || /^([a-zA-Z0-9._'-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,3})+$/i.test(value); }, "Please provide valid input"); jQuery.validator.addMethod("zipcodeRule", function(value, element) { return this.optional(element) || /^[a-zA-Z0-9 -]*$/i.test(value); }, "Please provide valid input"); jQuery.validator.addMethod("numberRule", function(value, element) { return this.optional(element) || /^[0-9]*$/i.test(value); }, "Please provide valid input"); jQuery.validator.addMethod("minCharRestriction", function(value, element) { return this.optional(element) || /^.{3,}$/i.test(value); }, "Please provide minimum 3 characters"); /***** Profiles ******/ jQuery.validator.addClassRules("inputValidation", { inputRule: true }); jQuery.validator.addClassRules("nameValidation", { nameRule: true }); jQuery.validator.addClassRules("emailValidation", { email:true }); jQuery.validator.addClassRules("numberValidation", { numberRule:true }); jQuery.validator.addClassRules("addressValidation", { addressRule: true }); jQuery.validator.addClassRules("phoneValidation", { phoneRule: true }); jQuery.validator.addClassRules("cityValidation", { cityRule: true }); jQuery.validator.addClassRules("splCharValidation", { splcharRule: true }); jQuery.validator.addClassRules("alphaNumericValidation", { alphaNumericRule: true }); jQuery.validator.addClassRules("spaceValidation", { spaceRule: true }); /**Validation to trim the search string */ jQuery.validator.addClassRules("alphaNumericValidationForSearchApplicant", { alphaNumericRuleForSearchApplicant: true }); jQuery.validator.addClassRules("applicantEmailValidation", { emailRule:true }); jQuery.validator.addClassRules("zipcodeValidation", { zipcodeRule:true }); /* commentValidation is same as splCharValidation except that it allows semi-colon */ jQuery.validator.addClassRules("commentValidation", { commentRule: true }); /* noLineBreakCommentValidation is used to validate the comment fields without showing comments with line break */ jQuery.validator.addClassRules("noLineBreakCommentValidation", { noLineBreakCommentRule: true }); /* commentValidationWithDoubleQuotes works same way as noLineBreakCommentValidation but it allws double quotes as well */ jQuery.validator.addClassRules("commentValidationWithDoubleQuotes", { commentValidationWithDoubleQuotesRule: true }); jQuery.validator.addClassRules("minimimumCharacterRestriction", { minCharRestriction: true });