Skip to content

Instantly share code, notes, and snippets.

@thomas479
Created July 21, 2016 07:14
Show Gist options
  • Save thomas479/056278b098f06eec16d4c112433e1e94 to your computer and use it in GitHub Desktop.
Save thomas479/056278b098f06eec16d4c112433e1e94 to your computer and use it in GitHub Desktop.
JQuery validator number extention. Allows both the decimal dot and decimal comma.
$.extend( $.validator.methods, {
number: function( value, element ) {
var result = false;
if(/^(?:-?\d+|-?\d{1,3}(?:,\d{3})+)?(?:,\d+)?$/.test( value )){
result = true;
} else if(/^(?:-?\d+|-?\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/.test( value )){
result = true;
}
return this.optional( element ) || result;
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment