ngPattern adds the pattern validator to ngModel. It is most often used for text-based input controls, but can also be applied to custom text-based controls.
The validator sets the pattern error key if the ngModel.$viewValue does not match a RegExp which is obtained from the ngPattern attribute value:
^ and $ characters. For instance, "abc" will be converted to new RegExp('^abc$').ngPattern="/^\d+$/", it is used directly.g flag on the RegExp, as it will cause each successive search to start at the index of the last search's match, thus not taking the whole input value into account. pattern attribute is used, with two differences: ngPattern does not set the pattern attribute and therefore HTML5 constraint validation is not available. ngPattern attribute must be an expression, while the pattern value must be interpolated. <ANY ng-pattern=""> ... </ANY>
| Param | Type | Details |
|---|---|---|
| ngPattern | expressionRegExp | AngularJS expression that must evaluate to a |
© 2010–2018 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://code.angularjs.org/1.7.8/docs/api/ng/directive/ngPattern