mirror of
https://github.com/jquery-validation/jquery-validation.git
synced 2025-12-20 09:11:40 +01:00
Pattern method: Convert string param to RegExp. Fixes issue #223
This commit is contained in:
@@ -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.");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user