Skip to content

Instantly share code, notes, and snippets.

@WillSams
Last active December 13, 2015 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WillSams/4945386 to your computer and use it in GitHub Desktop.
Save WillSams/4945386 to your computer and use it in GitHub Desktop.
Custom validators for use with jquery validate
jQuery.validator.addMethod("dateGreaterThan", function (value, element, params) {
if (!/Invalid|NaN/.test(new Date(value))) {
return new Date(value) > new Date($(params).val());
}
return isNaN(value) && isNaN($(params).val())
|| (Number(value) > Number($(params).val()));
}, '<br />Must be greater than {0}.');
jQuery.validator.addMethod('greaterThan', function (value, element, param) {
return (parseInt(value) > parseInt(param));
}, '<br />Must be greater than {0}');
jQuery.validator.addMethod('lesserThan', function (value, element, params) {
return (value < param);
}, '<br />Must be less than {0}');st row\'s value.');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment