The ng-minlength Directive in AngularJS is used to set the minimum length for an input field i.e it adds the restriction for an input field. It is different from minlength attribute in HTML because the former prevent users from entering less than the specified limit whereas the later doesn’t do that. It makes the form invalid if the entered input is less than the specified limit.
Syntax:
<element ng-minlength="expression"> content ... </element>
Where expression is a number denoting the minimum limit below which the input is invalid.
Example: This example uses ng-minlength Directive to set the minimum length of string.
<!DOCTYPE html> <html> <head> <title>ng-minlength Directive</title> <script src= </script> </head> <body style="text-align:center"> <h1 style="color:green">GeeksforGeeks</h1> <h2>ng-minlength Directive</h2> <div ng-app="app" ng-controller="geek"> <form name="minlength" novalidate ng-submit ="minlength.$valid &✓()"> <pre>Minimum 5 characters required</pre> Input: <input type="text" name="code" ng-model="txtpin" ng-minlength="5" required /> <br><br> <button type="submit">Click it</button> <br><br> <span>{{msg}}</span> </form> </div> <script> var app = angular.module('app', []); app.controller('geek', function ($scope) { $scope.check = function () { $scope.msg = "Input is valid"; }; }); </script> </body> </html> |
Output:
Before clicking the button:

After clicking the button:

Recommended Posts:
- AngularJS | ng-show Directive
- AngularJS | ng-init Directive
- AngularJS | ng-if Directive
- AngularJS | ng-dblclick Directive
- AngularJS | ng-keypress Directive
- AngularJS | ng-keydown Directive
- AngularJS | ng-keyup Directive
- AngularJS | ng-href Directive
- AngularJS | ng-focus Directive
- AngularJS | ng-hide Directive
- AngularJS | ng-disabled Directive
- AngularJs | ng-list Directive
- AngularJS | ng-mouseup Directive
- AngularJS | ng-mousedown Directive
- AngularJS | ng-maxlength Directive
- AngularJS | ng-mousemove Directive
- AngularJS | ng-mouseover Directive
- AngularJS | ng-mouseleave Directive
- AngularJS | ng-mouseenter Directive
- AngularJS | ng-copy Directive
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

