【发布时间】:2015-03-15 04:31:30
【问题描述】:
想要将电话号码设置为 10 位,我该如何使用 Angular js 来做到这一点。
这是我尝试过的:
<form class="form-horizontal" role="form" method="post" name="registration" novalidate>
<div class="form-group" ng-class="{'has-error': registration.phone.$error.number}">
<label for="inputPhone" class="col-sm-3 control-label">Phone :</label>
<div class="col-sm-9">
<input type="number"
class="form-control"
ng-minlength="10"
ng-maxlength="10"
id="inputPhone"
name="phone"
placeholder="Phone"
ng-model="user.phone"
ng-required="true">
<span class="help-block"
ng-show="registration.phone.$error.required &&
registration.phone.$error.number">
Valid phone number is required
</span>
<span class="help-block"
ng-show="((registration.password.$error.minlength ||
registration.password.$error.maxlength) &&
registration.phone.$dirty) ">
phone number should be 10 digits
</span>
</div>
</div>
</form>
但我没有收到验证错误。
【问题讨论】:
-
国际电话号码呢?
-
您的
ng-shows 正在寻找registration.phone,但您输入的ng-model是user.phone -
注册是表单名称我正在使用那个.. @rwacarter
标签: javascript angularjs angularjs-validation