Ng-Pattern-1

 

It sets pattern validation key if input field data does not match a RegularExpression that is bind to ng-pattern(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="mailForm"> Email: <input type="text" ng-model="mail" name="mail" ng-pattern="re" /><br /> <span ng-show="mailForm.mail.$error.pattern" style="color:red">Please enter correct email address.</span> </ng-form> </div> <script> var app = angular.module("app", []); app.controller('controllerName', ['$scope', function ($scope) { $scope.mail = "[email protected]"; $scope.re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i; }]); </script> </body> </html>
Output