PatternValidator
该指令会借助 NG_VALIDATORS
绑定来把 pattern
验证器添加到任何带有 pattern
属性的控件上。 它会使用该属性的值作为正则表达式来验证控件的值。 它会遵循 pattern
属性的语义,也就是说,该正则表达式必须匹配整个控件值。
A directive that adds regex pattern validation to controls marked with the pattern
attribute. The regex must match the entire control value. The directive is provided with the NG_VALIDATORS
multi-provider list.
参见
NgModules
选择器
[pattern][formControlName]
[pattern][formControl]
[pattern][ngModel]
属性
属性 | 说明 |
---|---|
@Input() | Tracks changes to the pattern bound to this directive. |
说明
添加模式(pattern)验证器
Adding a pattern validator
下面的例子演示了如何为一个带有 ngModel 绑定的输入框添加模式验证器。
The following example shows how to add a pattern validator to an input attached to an ngModel binding.
<input name="firstName" ngModel pattern="[a-zA-Z ]*">
方法
A lifecycle method called when the directive's inputs change. For internal use only. | |||
参数
返回值
|
Method that validates whether the value matches the the pattern requirement. | |||
参数
返回值
|
Registers a callback function to call when the validator inputs change. |