This is the archived documentation for Angular v6. Please visit angular.io to see documentation for the current version of Angular.

PatternValidator

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.

NgModules

Selectors

Properties

Property Description
@Input()
pattern: string | RegExp

Description

Example

<input [name]="fullName" pattern="[a-zA-Z ]*" ngModel>
      
      <input [name]="fullName" pattern="[a-zA-Z ]*" ngModel>
    

Methods

ngOnChanges(changes: SimpleChanges): void
      
      ngOnChanges(changes: SimpleChanges): void
    

Parameters

changes

Type: SimpleChanges.

Returns

void

validate(control: AbstractControl): ValidationErrors | null
      
      validate(control: AbstractControl): ValidationErrors | null
    

Parameters

control

Type: AbstractControl.

Returns

ValidationErrors | null

registerOnValidatorChange(fn: () => void): void
      
      registerOnValidatorChange(fn: () => void): void
    

Parameters

fn

Type: () => void.

Returns

void