Skip to content

Commit 9a6b3fb

Browse files
author
Duc Tri Le
committed
Merge pull request jquerytools#625 from rs/validator-optional-pattern
Fix pattern validator failing on optional fields if pattern doesn't allow empty value (Fix jquerytools#605)
2 parents 6dbd3ec + a451672 commit 9a6b3fb

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/validator/validator.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,8 @@
254254
return !!v;
255255
});
256256

257-
v.fn("[pattern]", function(el) {
258-
var p = new RegExp("^" + el.attr("pattern") + "$");
259-
return p.test(el.val());
257+
v.fn("[pattern]", function(el, v) {
258+
return v === '' || new RegExp("^" + el.attr("pattern") + "$").test(v);
260259
});
261260

262261
v.fn(":radio", "Please select an option.", function(el) {

0 commit comments

Comments
 (0)