AngularJs必填、比较、格式验证

界面:

  <form name="form" ng-submit="submitReg(tel,password,yzmsr,form)" novalidate="novalidate" >
                <!-- <h3><img src="/img/reh3.png" alt=""></h3> -->
                <div class="tb">
                    <dl class="sjh">
                        <dt>手机号</dt><dd><select name="" id=""><option value="">+86</option></select><input type="text" name="sjh" id="phone" ng-model="tel" ng-minlength="11"  required ng-pattern="/^1[3|4|5|7|8]\d{9}$/">
                        <p ng-show="form.submitted" class="error">                         
                               <small ng-show="form.sjh.$error.required">请输入手机号</small>
                                <small ng-show="form.sjh.$error.pattern">请填写正确的手机号</small>
                        </p>
                        </dd>   
                    </dl>
                    <dl class="yzm">
                        <dt>验证码</dt><dd><input type="text" ng-model="yzmsr" id="yzms"><button ng-click="yzm(tel)" class="hqyzm" type="button">获取验证码</button></dd>
                    </dl>
                    <dl>
                        <dt>输入密码</dt><dd><input type="password" id="password" name="password" ng-model="password" ng-minlength="6" ng-maxlength="20" required ng-pattern="/^[A-Za-z0-9]+$/">
                        <p ng-show="form.submitted" class="error">                    
                                <small ng-show="form.password.$error.required">请输入密码只能为6-20位字母与数字的组合</small>
                                <small ng-show="form.password.$error.minlength">密码长度最低6个字符</small>
                                <small ng-show="form.password.$error.maxlength">密码长度最高20个字符</small>
                                <small ng-show="form.password.$error.pattern">密码只能为6-20位字母与数字的组合</small>
                        </p>
                        </dd>
                    </dl>
                    <dl>
                        <dt>确认密码</dt><dd>
                        <input name="repassword" ng-model="formData.repassword" id="repassword" type="password" pw-check="password" required >
                        <p ng-show="form.submitted" class="error">                      
                              <small ng-show="form.repassword.$error.required">请输入密码只能为6-20位字母与数字的组合</small>
                                <small ng-show="form.repassword.$error.minlength">密码长度最低6个字符</small>
                                <small ng-show="form.repassword.$error.maxlength">密码长度最高20个字符</small>
                                <small ng-show="form.repassword.$error.pattern">密码只能为6-20位字母与数字的组合</small>
                                <small ng-show="form.repassword.$error.pwmatch">密码和确认密码不一致!!</small>
                        </p>
                        </dd>
                    </dl>
                </div>
                <div class="btn">
                    <button type="submit">确认注册</button>
                </div>
            </form>

脚本:

.controller('RegisterCtrl', function($scope, $http, $ionicPopup, $location, $window, myACcountsID, access_token, refresh_token, myDisplayName, myPhone, myPassword) {
    $scope.submitReg = function(t, p, y, form) {
        //判断数据是否完善
        //注册
        if(form.$valid) {
        //验证通过执行代码
        } else {
        //验证未通过
            form.submitted = true;
        }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值