angularJS ng-pattern无效
发布时间:2020-12-17 09:16:14 所属栏目:安全 来源:网络整理
导读:请看看plunker. http://plnkr.co/edit/DuTFYbLVbPkCIvRznYjG?p=preview 其中ng-pattern regEx不适用于输入文本字段. 只需要正确应用所需验证的地方. HTML: body ng-controller="tableController" form name="test" div ng-repeat="model in models" span ng
请看看plunker.
http://plnkr.co/edit/DuTFYbLVbPkCIvRznYjG?p=preview 其中ng-pattern regEx不适用于输入文本字段. 只需要正确应用所需验证的地方. 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",maxlength: 5,]; }); 有什么建议?? -谢谢
将正则表达式分配更改为以下.因为它应该是正则表达式.如果你用双引号提到那么它就变成了一个字符串.
$scope.regEx = /^d+$/; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |