jquery 比较常用的用户名验证、手机号验证、身份证件验证

<div class="qupiao">
    <h4>验证个人信息</h4>
    <form class="qupiao-ipt auth-form" action="">
        <div class="form-group">
            <label class="qupiao-ipt-1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;姓名:</label>
            <input id="name" type="text">
            <span class="checkExistRong" id="checkExistname"></span>
        </div>
        <div class="form-group">
            <label class="qupiao-ipt-2">身份证号码:</label>
            <input id="identity" type="text" name="fname" maxlength="18">
            <span class="checkExistRong" id="checkExistID"></span>

        </div>
        <div class="form-group">
            <label class="qupiao-ipt-3">手机号号码:</label>
            <input id="telephone" type="tel" name="fname" min="11">
            <span class="checkExistRong" id="checkExistPhone"></span>
        </div>
    </form>
</div>
/*姓名身份证,手机号提交*/
function isChinaName(name) {
    var pattern = /^[\u4E00-\u9FA5]{1,6}$/;
    return pattern.test(name);
}


// 验证身份证
function isCardNo(card) {
    var pattern = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
    return pattern.test(card);
}

// 验证手机号
function isPhoneNo(phone) {
    var pattern = /^1[34578]\d{9}$/;
    return pattern.test(phone);
}

/*用户名判断*/
function userName(inputid, spanid) {
    $(inputid).blur(function() {
        if ($.trim($(inputid).val()).length == 0) {
            $(spanid).html("× 名称没有输入");
        } else {
            if (isChinaName($.trim($(inputid).val())) == false) {
                $(spanid).html("× 名称不合法");
            }
        }
    });
    $(inputid).focus(function() {
        $(spanid).html("");
    });

};
userName('#name', "#checkExistname");
/*身份证判断*/
function userID(inputid, spanid) {
    $(inputid).blur(function() {
        if ($.trim($(inputid).val()).length == 0) {
            $(spanid).html("× 身份证号码没有输入");
        } else {
            if (isCardNo($.trim($(inputid).val())) == false) {
                $(spanid).html("× 身份证号不正确");
            }
        }
    });
    $(inputid).focus(function() {
        $(spanid).html("");
    });
};
userID('#identity', "#checkExistID");

/*手机号判断*/
function userTel(inputid, spanid) {
    $(inputid).blur(function() {
        if ($.trim($(inputid).val()).length == 0) {
            $(spanid).html("× 手机号没有输入");
        } else {
            if (isPhoneNo($.trim($(inputid).val())) == false) {
                $(spanid).html("× 手机号码不正确");
            }
        }
        $(inputid).focus(function() {
            $(spanid).html("");
        });
    });
};
userTel('#telephone', "#checkExistPhone");
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值