File tree 2 files changed +16
-1
lines changed
2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -2577,7 +2577,7 @@ var patternDirective = function() {
2577
2577
var regexp , patternExp = attr . ngPattern || attr . pattern ;
2578
2578
attr . $observe ( 'pattern' , function ( regex ) {
2579
2579
if ( isString ( regex ) && regex . length > 0 ) {
2580
- regex = new RegExp ( regex ) ;
2580
+ regex = new RegExp ( '^' + regex + '$' ) ;
2581
2581
}
2582
2582
2583
2583
if ( regex && ! regex . test ) {
Original file line number Diff line number Diff line change @@ -2224,6 +2224,21 @@ describe('input', function() {
2224
2224
} ) ;
2225
2225
} ) . toThrowMatching ( / ^ \[ n g P a t t e r n : n o r e g e x p \] E x p e c t e d f o o R e g e x p t o b e a R e g E x p b u t w a s / ) ;
2226
2226
} ) ;
2227
+
2228
+ it ( 'should be invalid if entire string does not match pattern' , function ( ) {
2229
+ compileInput ( '<input type="text" name="test" ng-model="value" pattern="\\d{4}">' ) ;
2230
+ changeInputValueTo ( '1234' ) ;
2231
+ expect ( scope . form . test . $error . pattern ) . not . toBe ( true ) ;
2232
+ expect ( inputElm ) . toBeValid ( ) ;
2233
+
2234
+ changeInputValueTo ( '123' ) ;
2235
+ expect ( scope . form . test . $error . pattern ) . toBe ( true ) ;
2236
+ expect ( inputElm ) . not . toBeValid ( ) ;
2237
+
2238
+ changeInputValueTo ( '12345' ) ;
2239
+ expect ( scope . form . test . $error . pattern ) . toBe ( true ) ;
2240
+ expect ( inputElm ) . not . toBeValid ( ) ;
2241
+ } ) ;
2227
2242
} ) ;
2228
2243
2229
2244
You can’t perform that action at this time.
0 commit comments