input验证 正则 代码示例

$(function(){    
    var name = $(".basic-information-item #name");
    var emil = $(".basic-information-item #emil");
    var btn = $(".basic-information-item #btn");
    var regMail = /[a-zA-Z0-9]{1,10}@[a-zA-Z0-9]{1,5}\.[a-zA-Z0-9]{1,5}/;
    var patrn=/^[a-zA-Z0-9\u4e00-\u9fa5]*$/;
    function checkname(){
        if(!patrn.test(name.val())){
            name.siblings('#ckerror').show().html("<i class='iconfont'></i> 请输入数字、汉字、字母");
            return false;
        }else if(name.val().length < 2){
            name.siblings('#ckerror').show().html("<i class='iconfont'></i> 至少输入2个字符");
            return false;
        }else{
            name.siblings('#ckerror').hide();
        }
    }
    function checkemail(){
        if (!regMail.test(emil.val())){
            emil.siblings('#ckerror').show().html("<i class='iconfont'></i> 请输入正确的邮箱");
            return false;
        }
        else {
            emil.siblings('#ckerror').hide();
        }
    }
    name.blur(function(){
        return checkname();
    });
    name.focus(function(){
        $(this).siblings('#ckerror').hide();
    });
    emil.blur(function(){
        return checkemail();
    });
    emil.focus(function(){
        $(this).siblings('#ckerror').hide();
    });
    btn.on('click',  function() {
        if(!patrn.test(name.val())){
            name.siblings('#ckerror').show().html("<i class='iconfont'></i> 请输入数字、汉字、字母");
            return false;
        }else if(name.val().length < 2){
            name.siblings('#ckerror').show().html("<i class='iconfont'></i> 至少输入2个字符");
            return false;
        }else{
            name.siblings('#ckerror').hide();
        }
        if(!regMail.test(emil.val())){
            emil.siblings('#ckerror').show().html("<i class='iconfont'></i> 请输入正确的邮箱");
            return false;
        }
        else {
            emil.siblings('#ckerror').hide();
        }
        //return true;
        document.myform.submit();
		//$("#myform").submit();
    });
});

验证昵称,邮箱,判断不全。。

转载于:https://www.cnblogs.com/luoluo8/p/5550057.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值