diff --git a/src/ng/directive/input.js b/src/ng/directive/input.js index 71456470cb91..2574360cc4e1 100644 --- a/src/ng/directive/input.js +++ b/src/ng/directive/input.js @@ -439,7 +439,8 @@ function textInputType(scope, element, attr, ctrl, $sniffer, $browser) { // pattern validator var pattern = attr.ngPattern, - patternValidator; + patternValidator, + match; var validate = function(regexp, value) { if (isEmpty(value) || regexp.test(value)) { @@ -452,8 +453,9 @@ function textInputType(scope, element, attr, ctrl, $sniffer, $browser) { }; if (pattern) { - if (pattern.match(/^\/(.*)\/$/)) { - pattern = new RegExp(pattern.substr(1, pattern.length - 2)); + match = pattern.match(/^\/(.*)\/([gim]*)$/); + if (match) { + pattern = new RegExp(match[1], match[2]); patternValidator = function(value) { return validate(pattern, value) }; diff --git a/test/ng/directive/inputSpec.js b/test/ng/directive/inputSpec.js index 4dcb79a38d12..d69be27c9e6d 100644 --- a/test/ng/directive/inputSpec.js +++ b/test/ng/directive/inputSpec.js @@ -476,6 +476,18 @@ describe('input', function() { }); + it('should validate in-lined pattern with modifiers', function() { + compileInput(''); + scope.$digest(); + + changeInputValueTo('aB'); + expect(inputElm).toBeValid(); + + changeInputValueTo('xx'); + expect(inputElm).toBeInvalid(); + }); + + it('should validate pattern from scope', function() { compileInput(''); scope.regexp = /^\d\d\d-\d\d-\d\d\d\d$/;