Permalink
Browse files

Merge pull request #625 from rs/validator-optional-pattern

Fix pattern validator failing on optional fields if pattern doesn't allow empty value (Fix #605)
  • Loading branch information...
2 parents 6dbd3ec + a451672 commit 9a6b3fb1494b8afa4303e23c6228de2628031d41 @duclet duclet committed Jan 19, 2012
Showing with 2 additions and 3 deletions.
  1. +2 −3 src/validator/validator.js
@@ -254,9 +254,8 @@
return !!v;
});
- v.fn("[pattern]", function(el) {
- var p = new RegExp("^" + el.attr("pattern") + "$");
- return p.test(el.val());
+ v.fn("[pattern]", function(el, v) {
+ return v === '' || new RegExp("^" + el.attr("pattern") + "$").test(v);
});
v.fn(":radio", "Please select an option.", function(el) {

0 comments on commit 9a6b3fb

Please sign in to comment.