Skip to content

Instantly share code, notes, and snippets.

@gilmoreorless
gilmoreorless / jquery-validator-extras.js
Created March 3, 2011 02:31
Extra validation methods for the jQuery Validate plugin
/*** Allow digits and whitespace ***/
// Method 1:
jQuery.validator.addMethod("digitsWhitespace", function(value, element) {
return this.optional(element) || /^[\d\s]+$/.test(value);
}, jQuery.validator.messages.digits);
// Method 2:
jQuery.validator.addMethod("digitsWhitespace", function(value, element) {
return jQuery.validator.methods.digits(value.replace(/\s/g, ''), element);