手机号,邮箱正则验证

var $mobile = $newAccBody.find('.mobile');
var $email = $newAccBody.find('.email');

//手机号输入框做限制
        function isPoneAvailable($phoneInput) {  
            var myreg=/^[1][3,4,5,7,8][0-9]{9}$/;
            if (!myreg.test($phoneInput.val())) {
                return false;  
            }  
        }
        $mobile.on('change',function(){
            if(isPoneAvailable($(this)) == false){
                util.notice('手机号输入有误!');
                $(this).val('').css('border-color','red').focus();
            }else{
                $(this).css('border-color','#e1e0e0');
            }
        });

//邮箱输入验证
        function isEmail($input){
            var reg = /^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/;
            if(!reg.test($input.val())){
                return false;
            }
        };
        $email.on('change',function(){
            if(isEmail($(this)) == false){
                util.notice('邮箱格式有误!');
                $(this).val('').css('border-color','red').focus();
            }else{
                $(this).css('border-color','#e1e0e0');
            }
        });

 

posted @ 2017-08-11 17:31  生命岂能苟且  阅读(247)  评论(0编辑  收藏  举报