【发布时间】:2015-11-06 20:39:56
【问题描述】:
我有脚本 here 并且 ng-pattern 工作正常,因为 scope.subnet 仅在输入匹配模式后才会显示在输出中。但是如果 ng-pattern 不匹配,ng-show 不会显示任何错误
<body ng-contoller="myConfigGenCtr">
<form novalidate name="myForm">
<div class="form-group">
<label for="hostname">Firewall hostname</label>
<input type="text" ng-model="hostname" class="form-control" id="hostname">
</div>
<div class="form-group">
<label for="subnet">Firewall subnet</label>
<input type="text" ng-model="subnet" class="form-control" id="subnet"
required ng-pattern="/^(?:[0-9]{1,3}\.){3}/" >
<div class="custom-error" ng-show="myForm.subnet.$error.pattern">
Not a valid subnet, should be i.e. 10.x.y. (3 bytes only)</div>
</div>
</form>
<div>Output: {{subnet}}</div>
</body>
【问题讨论】:
-
应该匹配什么模式?你能举个例子吗?
-
即1.1.1。它显示正常。但是如果我输入 1.1 错误不会出现
标签: javascript angularjs forms validation angularjs-forms