Skip to content

Instantly share code, notes, and snippets.

@carlosspohr
Last active June 21, 2016 23:58
Show Gist options
  • Save carlosspohr/57f7b31e5695c5f2b77a6ab6a078ce00 to your computer and use it in GitHub Desktop.
Save carlosspohr/57f7b31e5695c5f2b77a6ab6a078ce00 to your computer and use it in GitHub Desktop.
Collection of useful jquery.validate methods.
$.validator.addMethod("dateGreaterThan", function(value, element, params) {
var start = moment($(params).val(), "DD/MM/YYYY");
var end = moment(value, "DD/MM/YYYY");
return end.diff(start) >= 0;
}, "End date must be greater than start one.");
$.validator.addMethod("isValidDate_pt_BR", function(value, element) {
return moment(value, "DD/MM/YYYY").isValid();
}, "Invalid date");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment