【发布时间】:2015-09-08 05:27:20
【问题描述】:
我在验证电话号码时遇到问题。电话号码是一个 10 位的字符串,应填充在三个输入字段中 第一个输入字段 - 只有 3 位数字(要求,只能接受数字和最大长度 3) 第二个输入字段 - 只有 3 位数字(要求,只能接受数字和最大长度 3) 第三个输入字段 - 只有 4 位数字(要求,只能接受数字和最大长度 4)
当在第一个输入字段中实现最大字符数时,应将制表符移至下一个输入字段 当以上条件均不满足时,字段应为红色
<label for="phoneone" aria-label="Enter First 3 digits of your phone no."><input id="phoneone" type="number" required name="phoneone" class="phone-text-box" ng-model="user.phoneNumbercodeone" ng-minlength="3" ng-maxlength="3" maxlength="3" ng-pattern="/^[0-9]*$/"></input></label>
<label for="phonetwo" aria-label="Enter second 3 digits of your phone no."><input id="phonetwo" type="number" required name="phonetwo" class="phone-text-box" ng-model="user.phoneNumbercodetwo" ng-minlength="3" ng-maxlength="3" maxlength="3" ng-pattern="/^[0-9]*$/"></input></label>
<label for="phonethree" aria-label="Enter last 4 digits of your phone no."><input id="phonethree" type="number" required name="phonethree" class="phone-text-box" ng-model="user.phoneNumbercodethree" ng-minlength="4" ng-maxlength="4" maxlength="4" ng-pattern="/^[0-9]*$/"></input></label>
<div class="clearfix" ></div>
如何使用输入html标签实现上述验证条件
【问题讨论】:
-
如果你只想通过 html 标签进行验证,应该看起来像这样
<input type="number" name="phone[]" min="3" max="3" tabindex="1" required > -
我尝试了几个条件,但它不适合我。模式也应该只匹配数字
-
分享你到目前为止的尝试
-
请找到附件代码sn-p。上面的代码对我不起作用。我的代码有什么问题?
标签: javascript angularjs forms validation input