Pattern method: Convert string param to RegExp. Fixes issue #223

This commit is contained in:
gavacho
2012-02-22 11:49:06 -08:00
committed by Jörn Zaefferer
parent 520b6b7a18
commit 5dda6daa6c
2 changed files with 8 additions and 1 deletions

View File

@@ -295,6 +295,12 @@ jQuery.validator.addMethod("ipv6", function(value, element, param) {
* @cat Plugins/Validate/Methods
*/
jQuery.validator.addMethod("pattern", function(value, element, param) {
return this.optional(element) || param.test(value);
if (this.optional(element)) {
return true;
}
if (typeof param === 'string') {
param = new RegExp('^(?:' + param + ')$');
}
return param.test(value);
}, "Invalid format.");