Skip to main content
Version: 4.x (latest)

Custom Patterns

If none of the built-in patterns fit, add your own. Define the regex:

const customPattern = /^[a-zA-Z0-9.]+$/

Add a matching error message under pattern in your translation file (or errorMessages object):

{
"validations": {
"pattern": {
"customPattern": "The valid format is alphanumeric and the '.' is allowed"
}
}
}

Point the directive at it with patternKey:

<input
type="text"
formControlName="username"
placeholder="Username"
class="form-control"
ngxErrorMessage
patternKey="customPattern"
/>