Js常用的注册验证方法

原创
2019/04/10 20:06
阅读数 42
版权声明:转载请注明原创地址 https://blog.csdn.net/u013032788/article/details/49021207
<script type="text/javascript">
        $j(function(){
            /*获取短信息*/
                $j('.get-short-message').click(function(){
                    var is_get_message = CheckUserPhone();
                    if(is_get_message==false){
                        $j(".get-short-message").attr('disabled',true);
                        return false;
                    }else{
                        var UserPhone = $j.trim($j("#register_mobile").val());
                        var data = {"phone":UserPhone};
                        //60s以后重新获取
                        getShortMessagePassTime(this);
                        $j.get('/ajax/getMessageajax.php',data,function(res){
                            if(res==200){
                                errorMessage = "获取成功,请注意查收。" ;
                                $j("#short-message-error").text(errorMessage);
                            }else{
                                errorMessage = "获取失败" ;
                                $j("#short-message-error").text(errorMessage);
                            }
                        });
                        //60S后
                    }
                });
        });
        var waitTime=60;
        function getShortMessagePassTime(obj) {
            if (waitTime == 0) {
                obj.removeAttribute("disabled");
                obj.value="免费获取验证码";
                waitTime = 60;
            } else {
                obj.setAttribute("disabled", true);
                obj.value="重新发送(" + waitTime + ")";
                waitTime--;
                setTimeout(function() {
                        getShortMessagePassTime(obj)
                    },
                    1000)
            }
        }
        /***/
        function CheckUserPhone(){
            var UserPhone = $j.trim($j("#register_mobile").val());
            var errorMessage = null ;
            var ret = null;
            if(UserPhone.length == '')
            {
                errorMessage = "亲,手机不能为空哦" ;
                ret = false;

            }else if(!UserPhone.match(/^(1)\d{10}$/)){
                errorMessage = "亲,手机格式不对哦" ;
                ret = false;
            }else{
                var UserPhone = $j.trim($j("#register_mobile").val());
                var data={"UserPhone":UserPhone};
                $j.ajax({
                    type: "GET",
                    async:false,//默认是true
                    url: "/customer/account/createpost",
                    data: data,
                    success:function(rs, st){
                        if(rs=='110'){
                            errorMessage = "手机已经被注册过,请换一个哦" ;
                            ret = false;
                            //$j("#short-message-error").text(errorMessage);
                        }else{
                            errorMessage = "" ;
                            $j(".error-message").addClass('Ok');
                            $j(".get-short-message").attr('disabled',false);
                            ret = true;
                        }
                    }
                })

            }
            $j("#phone-error-message").text(errorMessage);
            return ret;
        }

        function CheckUserEmai(){
            var UserEmail = $j.trim($j("#email_address").val());
            var errorMessage = null;
            var ret = null;
            if(UserEmail.length == ''){
                errorMessage = "亲,邮箱不能为空哦" ;
                ret = false;

            }else if(!UserEmail.match(/^[a-z0-9]([a-z0-9]*[-_.]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[\.][a-z]{2,4}([\.][a-z]{2,4})?$/i)){
                errorMessage = "亲,邮箱格式不正确哦" ;
                ret = false;
            }else{
                var UserEmail = $j.trim($j("#email_address").val());
                var data={"UserEmail":UserEmail};
                $j.ajax({
                    type: "GET",
                    async:false,//默认是true
                    url: "/customer/account/createpost",
                    data: data,
                    success:function(rs, st){
                        if(rs=='120'){
                            errorMessage = "邮箱已经被注册过,请换一个哦" ;
                            ret = false;
                            //$j("#short-message-error").text(errorMessage);
                        }else{
                            errorMessage = "" ;
                            ret = true;
                        }
                    }
                })
            }
            $j("#email_address_span").text(errorMessage);
            return ret;

        }
        function CheckUserPassword(){
            var UserPassword = $j.trim($j("#password").val());
            var errorMesage = null;
            var ret = null;
            if(UserPassword.length == ""){
                errorMessage = "亲,密码不能为空哦" ;
                ret = false;

            }else if(UserPassword.length < 6){
                errorMessage = "亲,密码不能小于六位数哦" ;
                ret = false;
            }else{
                errorMessage = "" ;
                ret = true;
            }
            $j("#passwd-span").text(errorMessage);
            return ret;
        }
        function CheckUserRepassword(){
            var Repassword = $j.trim($j("#confirmation").val());
            var Password = $j.trim($j("#password").val());
            var errorMessage = null;
            var ret = null;
            if(Repassword.length == ""){
                errorMessage = "亲,重复密码不能为空哦";
                ret = false;
            }else if(Repassword != Password){
                errorMessage = "亲,两次密码输入的不一致哦" ;
                ret = false;
            }else{
                errorMessage = "" ;
                ret = true;
            }
            $j("#confirmation-span").text(errorMessage);
            return ret;
        }
        function CheckShortMessage(){
            var result = false;
            var errorMessage = null;            var ShortMessage = $j.trim($j("#get-message").val());
            if(ShortMessage.length == ""){
                errorMessage = "短信不能为空";
                result = false;
            }else if(ShortMessage.length != 6){
                errorMessage = "短信必须是6位数字" ;
                result = false;
            }else{
                var UserPhone = $j.trim($j("#register_mobile").val());
                var data={"ShortMessage":ShortMessage,"UserPhone":UserPhone};
                $j.ajax({
                    type: "GET",
                    async:false,//默认是true
                    url: "/ajax/identifyinCodeajax.php",
                    data: data,
                    success:function(data, st){
                        if(data=='200'){
                             errorMessage ="";
                            result = true;
                        }else{
                            errorMessage = "短信已失效,请重新获取哦" ;
                            result = false;
                        }
                    }
                })
            }
            $j("#short-message-error").text(errorMessage);
            return result;
        }


        function CheckAgreement(){
            var errorMessage = null;
            var ret = null;
            if($j('#is_subscribed').is(':checked')){
                errorMessage = '';
                ret = true;
              }else{
                  errorMessage = "亲,请接受服务条款";
                  ret = false;
                  }
            $j("#agreement-message-error").text(errorMessage);
            return ret;
        }

        $j("#register_mobile").blur(function(){
            CheckUserPhone();
        });
        $j("#email_address").blur(function(){
            CheckUserEmai();
        });
        $j("#password").blur(function(){
            CheckUserPassword();
        });
        $j("#confirmation").blur(function(){
            CheckUserRepassword();
        });

        $j("#submit-button").click(function(){
            if(CheckAgreement()==false){
                return false;
            }else if(CheckUserPhone() == false){
                return false;
            }else if(CheckUserEmai() == false){
                return false;
            }else if(CheckUserPassword() == false){
                return false;
            }else if(CheckUserRepassword() == false){
                return false;
            }else if(CheckShortMessage()==false){
                return false;
            }else{
                $j("#form-validate").submit();
            }
        });
<!--        //<![CDATA[-->
<!--        var dataForm = new VarienForm('form-validate', true);-->
<!--        --><?php //if($this->getShowAddressFields()): ?>
<!--        new RegionUpdater('country', 'region', 'region_id', --><?php //echo $this->helper('directory')->getRegionJson() ?><!--, undefined, 'zip');-->
<!--        --><?php //endif; ?>
<!--    //]]>-->

    </script>


二当家的官网,请访问 http://www.erdangjiade.com

更多商城企业源码,尽在 http://www.erdangjiade.com/source

更多原创模板,尽在 http://www.erdangjiade.com/templates  

网页特效下载:www.erdangjiade.com/js

PHP/Mysql:www.erdangjiade.com/php
     
PHP网站开发求职QQ群 368848856

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部