File tree 2 files changed +14
-1
lines changed
2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -163,7 +163,14 @@ export class Validators {
163
163
let regex : RegExp ;
164
164
let regexStr : string ;
165
165
if ( typeof pattern === 'string' ) {
166
- regexStr = `^${ pattern } $` ;
166
+ regexStr = '' ;
167
+
168
+ if ( pattern . charAt ( 0 ) !== '^' ) regexStr += '^' ;
169
+
170
+ regexStr += pattern ;
171
+
172
+ if ( pattern . charAt ( pattern . length - 1 ) !== '$' ) regexStr += '$' ;
173
+
167
174
regex = new RegExp ( regexStr ) ;
168
175
} else {
169
176
regexStr = pattern . toString ( ) ;
Original file line number Diff line number Diff line change @@ -270,6 +270,12 @@ import {map} from 'rxjs/operator/map';
270
270
271
271
it ( 'should not error on "undefined" pattern' ,
272
272
( ) => expect ( Validators . pattern ( undefined ! ) ( new FormControl ( 'aaAA' ) ) ) . toBeNull ( ) ) ;
273
+
274
+ it ( 'should work with string containing line boundary' ,
275
+ ( ) => expect ( Validators . pattern ( '^[aA]*$' ) ( new FormControl ( 'aaAA' ) ) ) . toBeNull ( ) ) ;
276
+
277
+ it ( 'should work with string not containing line boundary' ,
278
+ ( ) => expect ( Validators . pattern ( '[aA]*' ) ( new FormControl ( 'aaAA' ) ) ) . toBeNull ( ) ) ;
273
279
} ) ;
274
280
275
281
describe ( 'compose' , ( ) => {
You can’t perform that action at this time.
0 commit comments