PatternValidator
directive
npm Package | @angular/forms |
---|---|
Module | import { PatternValidator } from '@angular/forms'; |
Source | forms/src/directives/validators.ts |
Overview
@Directive({ selector: '[pattern][formControlName],[pattern][formControl],[pattern][ngModel]', providers: [PATTERN_VALIDATOR], host: { '[attr.pattern]': 'pattern ? pattern : null' } }) class PatternValidator implements Validator, OnChanges { pattern: string|RegExp ngOnChanges(changes: SimpleChanges): void validate(c: AbstractControl): ValidationErrors|null registerOnValidatorChange(fn: () => void): void }
Selectors
[pattern][formControlName]
[pattern][formControl]
[pattern][ngModel]
Inputs
pattern
bound to PatternValidator.pattern
Description
A Directive that adds the pattern
validator to any controls marked with the pattern
attribute, via the NG_VALIDATORS
binding. Uses attribute value as the regex to validate Control value against. Follows pattern attribute semantics; i.e. regex must match entire Control value.
Example
<input [name]="fullName" pattern="[a-zA-Z ]*" ngModel>
Members
pattern: string|RegExp
ngOnChanges(changes: SimpleChanges): void
validate(c: AbstractControl): ValidationErrors|null
registerOnValidatorChange(fn: () => void): void
© 2010–2017 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://v4.angular.io/api/forms/PatternValidator