Ng-Pattern-5

 
In this we should only write digits not more than 6 but between 0-9 in textbox otherwise it will give error.
 
 
 
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script> </head> <body ng-app="app"> <div ng-controller="controllerName"> <ng-form name="numberForm"> Number Only:<input type="text" ng-model="number" name="number" ng-pattern="re" /><br /> <span ng-show="numberForm.number.$error.pattern" style="color:red">Enter only number.</span> </ng-form> </div> <script> var app = angular.module("app", []); app.controller('controllerName', ['$scope', function ($scope) { $scope.re = /^[0-9]{1,6}$/; }]); </script> </body> </html>
Output