Ng-Pattern-3

 

It sets the pattern validation key if input field data does not match a RegularExpression that is bind to ng-pattern directive(re).

 
 
 
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <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="landLineForm"> Land Line #: <input type="text" ng-model="landLine" name="landLine" ng-pattern="re" /> <br /> <span ng-show="landLineForm.landLine.$error.pattern" style="color:red">Please enter valid Land Line number.</span> </ng-form> </div> <script> var app = angular.module("app", []); app.controller('controllerName', ['$scope', function ($scope) { $scope.re = /^[0-9]\d{2,5}-\d{6,8}$/; }]); </script> </body> </html>
Output