Skip to content

Instantly share code, notes, and snippets.

@FabianoFaria
Created February 2, 2017 19:35
Show Gist options
  • Save FabianoFaria/ad66489a8c4fc10599c7b72724c14532 to your computer and use it in GitHub Desktop.
Save FabianoFaria/ad66489a8c4fc10599c7b72724c14532 to your computer and use it in GitHub Desktop.
Data x maior que yy, formato 'yyyy/mm-dd'
/*
* Valida se a data fina é maior que a data inicio
*/
jQuery.validator.addMethod("greaterThan",
function(value, element, params) {
var temp = value.split("/");
var temp2 = $(params).val().split("/");
if (!/Invalid|NaN/.test(new Date(temp[2], (temp[1] - 1), temp[0]))) {
return new Date(temp[2], (temp[1] - 1), temp[0]) > new Date(temp2[2], (temp2[1] - 1), temp2[0]);
}
return isNaN(value) && isNaN($(params).val())
|| (Number(value) > Number($(params).val()));
},'Must be greater than {0}.');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment