Last active
May 27, 2021 16:40
-
-
Save ajay-ag/845b56c40fcc39ee6b692375209d48f9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.validator.addMethod("pan", function (value, element) { | |
return this.optional(element) || /^[A-Z]{5}\d{4}[A-Z]{1}$/.test(value); | |
}, "Please enter a valid PAN"); | |
$.validator.addMethod("gst", function (value, element) { | |
return this.optional(element) || /^([0]{1}[1-9]{1}|[1-2]{1}[0-9]{1}|[3]{1}[0-7]{1})([a-zA-Z]{5}[0-9]{4}[a-zA-Z]{1}[1-9a-zA-Z]{1}[zZ]{1}[0-9a-zA-Z]{1})+$/.test(value); | |
}, "Please enter a valid GST No"); | |
$.validator.addMethod('filesize', function (value, element, param) { | |
if (element.files.length) { | |
return this.optional(element) || (element.files[0].size <= param) | |
} | |
return true; | |
}, 'File size must be less than 5mb.'); | |
$.validator.addMethod("unique", function(value, element, params) { | |
var prefix = params; | |
var selector = jQuery.validator.format("[name!='{0}']{1}", element.name, prefix); | |
var matches = new Array(); | |
$(selector).each(function(index, item) { | |
if (value == $(item).val()) { | |
matches.push(item); | |
} | |
}); | |
return matches.length == 0; | |
}, "Value is not unique."); | |
$.validator.addMethod('lessThanEqual', function (value, element, param) { | |
return this.optional(element) || parseInt(value) <= parseInt($(param).val()); | |
},function (params, element) { | |
console.log(params, element); | |
return "The value " + $(element).val() + " must be less than or equal " + $(params).val(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment