Ng-Pattern-2

 

It sets pattern validation key if input field data does not match a RegularExpression that is bind to ng-pattern(re).In this correct form of mobile number show in placeholder.

 
 
 
<!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="mobileForm"> Mobile: <input type="text" ng-model="mobile" name="mobile" placeholder="+91-9855514371" ng-pattern="re" /> <br /> <span ng-show="mobileForm.mobile.$error.pattern" style="color:red">Mobile number should be in valid formate.</span> </ng-form> </div> <script> var app = angular.module("app", []); app.controller('controllerName', ['$scope', function ($scope) { $scope.re = /^(\+\91{1,2}[- ])\d{10}$/; }]); </script> </body> </html>
Output