Tutorials Exercises Get Certified Services Menu
Log in
Sign Up Spaces Bootcamps

AngularJS ng-minlength Directive


Display an error if the input value is shorter than five characters:

<form name="myForm">

<input name="myInput" ng-model="myInput" ng-minlength="5">

<h1 ng-if="!myForm.myInput.$valid">The value is too short</h1>

Try it Yourself »

Definition and Usage

The ng-minlength directive adds a restriction to an input field, and to the validator of the form.

The ng-minlength directive will add an "invalid" state of the input field if the length of the value is less than specified.

Note: If the value is empty, it is considered valid.


<input type="text" ng-minlength="number"></input>

Mainly supported by <input> elements of type text, but can also be used on other elements that allows user input.

Parameter Values

Value Description
number A number representing the minimum number of characters legal for the input field.