From 7e8ec77edac4b25e3d83724642614ebb914ad444 Mon Sep 17 00:00:00 2001 From: Lenard Gunda Date: Mon, 24 Jul 2017 16:05:43 +0300 Subject: [PATCH] Added flags parameter to regexp validation rule to allow case insensitive regexps --- src/jquery.validate.unobtrusive.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/jquery.validate.unobtrusive.js b/src/jquery.validate.unobtrusive.js index 57a2657..e20cc5d 100644 --- a/src/jquery.validate.unobtrusive.js +++ b/src/jquery.validate.unobtrusive.js @@ -342,7 +342,7 @@ return true; } - match = new RegExp(params).exec(value); + match = new RegExp(params.pattern, params.flags).exec(value); return (match && (match.index === 0) && (match[0].length === value.length)); }); @@ -365,7 +365,17 @@ adapters.addSingleVal("extension", "extension", "accept"); } - adapters.addSingleVal("regex", "pattern"); + adapters.add("regex", ["pattern", "flags"], function (options) { + if (options.params.pattern) { + var params = { + pattern: options.params.pattern + }; + if (options.params.flags) { + params["flags"] = options.params.flags; + } + setValidationValues(options, "regex", params); + } + }); adapters.addBool("creditcard").addBool("date").addBool("digits").addBool("email").addBool("number").addBool("url"); adapters.addMinMax("length", "minlength", "maxlength", "rangelength").addMinMax("range", "min", "max", "range"); adapters.addMinMax("minlength", "minlength").addMinMax("maxlength", "minlength", "maxlength");