AngularJS expression that must evaluate to a RegExp or a String
parsable into a RegExp, or a RegExp literal. See above for
more details.
Description
ngPattern adds the pattern ngModel.NgModelController#$validators validator to ngModel ngModel.
It is most often used for text-based input input controls, but can also be applied to custom text-based controls.
The validator sets the pattern error key if the ngModel.NgModelController#$viewValue ngModel.$viewValue
does not match a RegExp which is obtained from the ngPattern attribute value:
the value is an AngularJS expression:
If the expression evaluates to a RegExp object, then this is used directly.
If the expression evaluates to a string, then it will be converted to a RegExp after wrapping it
in ^ and $ characters. For instance, "abc" will be converted to new RegExp('^abc$').
If the value is a RegExp literal, e.g. ngPattern="/^\d+$/", it is used directly.
**Note:** Avoid using the `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.
**Note:** This directive is also added when the plain `pattern` attribute is used, with two
differences:
`ngPattern` does not set the `pattern` attribute and therefore HTML5 constraint validation is
not available.
The `ngPattern` attribute must be an expression, while the `pattern` value must be
interpolated.
Param: ngPattern
AngularJS expression that must evaluate to a
RegExp
or aString
parsable into aRegExp
, or aRegExp
literal. See above for more details.Description
ngPattern adds the pattern ngModel.NgModelController#$validators
validator
to ngModelngModel
. It is most often used for text-based inputinput
controls, but can also be applied to custom text-based controls.The validator sets the
pattern
error key if the ngModel.NgModelController#$viewValuengModel.$viewValue
does not match a RegExp which is obtained from thengPattern
attribute value:^
and$
characters. For instance,"abc"
will be converted tonew RegExp('^abc$')
.ngPattern="/^\d+$/"
, it is used directly.