{ "id": "api/forms/PatternValidator", "title": "PatternValidator", "contents": "\n\n
\n
\n
\n \n API > @angular/forms\n
\n \n
\n \n
\n

PatternValidatorlink

\n \n \n \n \n \n
\n \n \n\n
\n \n
\n

A directive that adds regex pattern validation to controls marked with the\npattern attribute. The regex must match the entire control value.\nThe directive is provided with the NG_VALIDATORS multi-provider list.

\n\n \n
\n \n \n \n \n
\n

See alsolink

\n \n
\n\n\n

NgModuleslink

\n\n\n\n \n
\n

Selectorslink

\n \n \n \n
\n\n\n\n \n\n
\n

Propertieslink

\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
PropertyDescription
\n \n @Input()
pattern: string | RegExp
\n
\n \n

Tracks changes to the pattern bound to this directive.

\n\n \n
\n
\n\n\n\n \n\n\n \n
\n

Descriptionlink

\n \n

Adding a pattern validatorlink

\n

The following example shows how to add a pattern validator to an input attached to an\nngModel binding.

\n\n<input name=\"firstName\" ngModel pattern=\"[a-zA-Z ]*\">\n\n\n
\n \n\n \n\n \n\n \n\n \n \n \n\n
\n
\n\n\n" }