【发布时间】:2015-08-28 19:23:47
【问题描述】:
我正在尝试使用 ng-pattern 验证文本框中的 IP 地址
代码:
<input name="machinestodiscover" type="text" ng-model="machinestodiscover" ng-minlength="7" ng-maxlength="15" ng-pattern="/\b([0-9]{1,3})[.]([0-9]{1,3})[.]([0-9]{1,3})[.]([0-9]{1,3})\b/" required>
<span ng-show="conditionForm.machinestodiscover.$error.required" class="help-block" style="display:inline;">*Machines To discover Required</span>
<span ng-show="conditionForm.machinestodiscover.$error.pattern" class="help-block" style="display:inline;">*IP Pattern Wrong.</span>
我面临的问题是它甚至接受 1.1.1.1.1.1.1 的值。
当我检查http://regexr.com/中的表达式时
截图:
我的正则表达式/ng-pattern 有什么问题
【问题讨论】:
-
试试stackoverflow.com/questions/10006459/…中提供的正则表达式
标签: javascript html regex angularjs