validation - angularJS ng-pattern not working -
please take plunker.
http://plnkr.co/edit/dutfyblvbpkcivrznyjg?p=preview
where ng-pattern regex not going apply on input text field.
where required validation applying properly.
html:
<body ng-controller="tablecontroller"> <form name="test"> <div ng-repeat="model in models"> <span ng-bind="model.caption"></span> <div ng-form name="frm{{$index}}"> <input name="input{{$index}}" ng-model="data[model.name]" ng-disabled="model.isdisabled" minlength="{{model.minlength}}" maxlength="{{model.maxlength}}" ng-show="model.isshow" ng-pattern="model.pattern" ng-required="true" /> <br /> {{data[model.name]}} </div> </div> </form> <br /> <br /> </body>
js:
angular.module("app", []).controller("tablecontroller", function ($scope) { $scope.regex = "/^\\d+$/"; $scope.data = {}; $scope.data.one = 234; $scope.data.two = 32432; $scope.models = [ { name: "one", caption: "cone", isdisabled: false, isshow: true, minlength: 2, maxlength: 10, pattern: "/^\d+$/" }, { name: "two", caption: "ctwo", isdisabled: false, isshow: true, minlength: 2, maxlength: 5, pattern: "/^\d+$/" }, ]; });
any suggestion ??
-thanks
change regular expression assignment below. since should regular expression. if mention in double quotes becomes string.
$scope.regex = /^\d+$/;
Comments
Post a Comment