Using the built-in form validators
We already saw that we can alter validation behavior to any control by using the required
attribute. Angular 2 provides two more built-in validators, as follows:
minlength
: Allows us to specify the minimum length of the value that a given control should have.maxlength
: Allows us to specify the maximum length of the value that a given control should have.
These validators are defined with Angular 2 directives and can be used in the following way:
<input id="realNameInput" class="form-control" type="text" ngControl="realName" minlength="2" maxlength="30">
This way, we specify that we want the value of the input to be between 2
and 30
characters