Skip to content

Instantly share code, notes, and snippets.

@pawar-aniket
Last active September 14, 2017 12:29
Show Gist options
  • Save pawar-aniket/3d8ba5fa5a8655262fd34ecfa7a1a147 to your computer and use it in GitHub Desktop.
Save pawar-aniket/3d8ba5fa5a8655262fd34ecfa7a1a147 to your computer and use it in GitHub Desktop.
jQuery.validator.addMethod("alphanumeric", function(value, element) {
return this.optional(element) || /^[A-Za-z0-9 _]*[A-Za-z0-9][A-Za-z0-9 _]*$/.test(value);
});
jQuery.validator.addMethod("letterwithspaces", function(value, element) {
return this.optional(element) || /^[a-zA-Z\s]+$/.test(value);
});
jQuery.validator.addMethod("imagetype", function(value, element) {
return this.optional(element) || /^.*\.(jpg|png|jpeg|gif)$/i.test(value);
}, "Please Select .jpg OR .png OR .gif Image");
jQuery.validator.addMethod("filetype", function(value, element) {
return this.optional(element) || /^.*\.(doc|docx|pdf)$/i.test(value);
}, "Please Select .doc OR .docx OR .pdf Image");
jQuery.validator.addMethod('filesize', function(value, element, param) {
// param = size (in bytes)
// element = element to validate (<input>)
// value = value of the element (file name)
return this.optional(element) || (element.files[0].size <= param)
});
jQuery.validator.addMethod("lettersonly", function(value, element) {
return this.optional(element) || /^[a-z ]+$/i.test(value);
}, "Please enter alphanumeric letters only");
jQuery.validator.addMethod("noSpace", function(value, element) {
return value.indexOf(" ") < 0 && value != "";
}, "Please enter valid account number");
jQuery.validator.addMethod(
"regex",
function(value, element, regexp) {
var re = new RegExp(regexp);
return this.optional(element) || re.test(value);
},
"Please enter valid format."
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment