AngularJS ng-minlength Directive
Definition and Usage
ng-minlength
The instruction adds restrictions to the input field and form validators.
If the length of the value of the input field is less than the specified length,ng-minlength
The directive will add an 'invalid' status.
Note:If the value is empty, it is considered valid.
Example
If the input value is less than five characters, an error will be displayed:
<form name="myForm"> <input name="myInput" ng-model="myInput" ng-minlength="5"> <h1 ng-if="!myForm.myInput.$valid">The value is too short</h1> </form>
Syntax
<input type="text" ng-minlength="number"></input>
Primarily used for text-based <input>
Element supported, but can also be used for other elements that allow user input.
Parameter
Parameter | Description |
---|---|
number | A number representing the minimum number of characters allowed for an input field. |