Home
Tutorials
Microsoft Technologies Tutorials
Java Programming Tutorials
Web Designing Tutorials
Script Programming Tutorials
Database Programming Tutorials
Mobile Technologies Tutorials
Other Programming Tutorials
Examples
Articles
Tools
News
AngularJS ng-minlength, ng-maxlength Validation Example
Keywords : Angularjs minimum length and maximum length validation example, How to use ng-minlength / maxlength properties in angularjs with example, Angularjs min, max length validation example
Example
<!DOCTYPE html> <html> <head> <title> AngularJs Example to Use Both ng-minlength, ng-maxlength for Form Validation </title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> <script type="text/javascript"> var app = angular.module('ngminmaxlengthApp', []); app.controller('ngminmaxlengthCtrl', function ($scope) { $scope.sendForm = function () { $scope.msg = "Form Validated"; }; }); </script> </head> <body> <div ng-app="ngminmaxlengthApp" ng-controller="ngminmaxlengthCtrl"> <h3>AngularJs Example to Use Both ng-minlength, ng-maxlength</h3> <form name="personForm" novalidate ng-submit="personForm.$valid &&sendForm()"> Pin Code: <input type="text" name="pincode" ng-model="txtpin" ng-minlength="3" ng-maxlength="5" required /> <span style="color:Red" ng-show="personForm.pincode.$error.required"> Required! </span> <span style="color:Red" ng-show="personForm.pincode.$dirty&&personForm.pincode.$error.minlength"> Minimum 3 Characters Required </span> <span style="color:Red" ng-show="personForm.pincode.$dirty&&personForm.pincode.$error.maxlength"> Maximum 5 Characters Allowed </span> <br /><br /> <button type="submit">Submit Form</button><br /><br /> <span>{{msg}}</span> </form> </div> </body> </html>
Click Here to See Result
Result
Previous
Next