Skip to content

Instantly share code, notes, and snippets.

@joeRinehart
Created July 17, 2018 13:31
Show Gist options
  • Save joeRinehart/0e8af523fdfc567cc670ddca2eaff137 to your computer and use it in GitHub Desktop.
Save joeRinehart/0e8af523fdfc567cc670ddca2eaff137 to your computer and use it in GitHub Desktop.
/*
See https://github.com/jquery-validation/jquery-validation/issues/379.
The maintainors of jQuery validate are OK validating whether or not 1,000,000 and 1.000.000 are numbers,
but aren't getting into parsing their values (because of international formats), so the min, max, and range
rules don't support anything formatted.
*/
$.validator.addMethod('min', function( value, element, param ) {
value = numeral(value).value();
return this.optional(element) || value >= param;
});
$.validator.addMethod('max', function( value, element, param ) {
value = numeral(value).value();
return this.optional(element) || value <= param;
});
$.validator.addMethod('range', function( value, element, param ) {
value = numeral(value).value();
return this.optional(element) || ( value >= param[0] && value <= param[1] );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment