An angular ng-patter is check the matching value of input string in directive and return a form validation. Ng-pattern is value match logic are applied form user input on DOM End. I set the pattern value is amazon while enter the input box value is amazon mean return true from form validation other than false.
HTML:
<div ng-app="PatternApp">
<div ng-controller="PtrnCtrl">
<form name="ptrfrm">
<input type="text" ng-model="model" id="input" name="input" ng-pattern="ptrn" /><br>
Result==> {{ptrfrm.input.$valid}}
</form>
</div>
Angular:
var app = angular.module('PatternApp',[]);
app.controller('PtrnCtrl', function($scope){
$scope.ptrn = "amazon";
});
Result:
Demo
HTML:
<div ng-app="PatternApp">
<div ng-controller="PtrnCtrl">
<form name="ptrfrm">
<input type="text" ng-model="model" id="input" name="input" ng-pattern="ptrn" /><br>
Result==> {{ptrfrm.input.$valid}}
</form>
</div>
Angular:
var app = angular.module('PatternApp',[]);
app.controller('PtrnCtrl', function($scope){
$scope.ptrn = "amazon";
});
Result:
Demo
Comments
Post a Comment