采用了棱角分明的JS验证电话号码 [英] Validate phone number using angular js

查看:108
本文介绍了采用了棱角分明的JS验证电话号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置的电话号码恰好10位,我怎么可以这样采用了棱角分明的js实现的。结果
这是我曾尝试搜索

I want to set phone number to exactly 10 digits, How can I achieve this using angular js.
This is what i have tried

<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>


</form>

结果

但我没有得到验证错误。

But I am not getting validation error.

推荐答案

试试这个:

<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.phone.$error.minlength || registration.phone.$error.maxlength) && registration.phone.$dirty) ">phone number should be 10 digits</span>

这篇关于采用了棱角分明的JS验证电话号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆