Skip to content

Instantly share code, notes, and snippets.

@devsuperman
Last active January 28, 2019 14:52
Show Gist options
  • Save devsuperman/a884cff9f792a017898a3ef4c78956f0 to your computer and use it in GitHub Desktop.
Save devsuperman/a884cff9f792a017898a3ef4c78956f0 to your computer and use it in GitHub Desktop.
Método de extensão do jQuery para validar data e números em formato brasileiro
//Substitui o ponto pela virgula ao validar inputs decimais. Muito adequado para inputs de valor monetário.
$.validator.methods.range = function (value, element, param) {
var globalizedValue = value.replace(",", ".");
return this.optional(element) || (globalizedValue >= param[0] && globalizedValue <= param[1]);
};
$.validator.methods.number = function (value, element) {
return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:[\s\.,]\d{3})+)(?:[\.,]\d+)?$/.test(value);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment