AngularJs必填、比较、格式验证

界面:

  <form name="form" ng-submit="submitReg(tel,password,yzmsr,form)" novalidate="novalidate" >
                
                <div class="tb">
                    <dl class="sjh">
                        <dt>手机号dt><dd><select name="" id=""><option value="">+86option>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;
        }
}

你可能感兴趣的:(AngularJs)