Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

AngularJS | ng-minlength Directive

  • Last Updated : 26 Mar, 2019

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.


<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>
    <title>ng-minlength Directive</title>
    <script src=
<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 &&check()">
            <pre>Minimum 5 characters required</pre>
            Input: <input type="text" name="code" ng-model="txtpin"
                    ng-minlength="5" required />
            <button type="submit">Click it</button>
        var app = angular.module('app', []);
        app.controller('geek', function ($scope) {
            $scope.check = function () {
                $scope.msg = "Input is valid";

Before clicking the button:
After clicking the button:

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!