邮箱,手机号,电话号,身份证,中文名称验证

邮箱,手机号,电话号,身份证,中文名称验证

<script type="text/javascript">
    //验证邮箱
    function emailZ(obj){
        var email=document.getElementById(obj).value;
        if(email!=""){
            if(!email.match(/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/))
            {
                alert("The mailbox format is incorrect! Please re-enter");
                $("#"+obj).val("");
                $("#"+obj).focus();
                return false;
            }
        }
    }
    // 验证手机号
    function isPhoneNo(phone) {
        var pattern=document.getElementById(phone).value;
        if(pattern!=""){
            if(!pattern.match(/^1[34578]\d{9}$/))
            {
                alert("The phone number is not in the correct format! Please re-enter");
                $("#"+phone).val("");
                $("#"+phone).focus();
                return false;
            }
        }
    }
    // 验证电话号
    function isContact(phone) {
        var pattern=document.getElementById(phone).value;
        if(pattern!=""){
            if(!pattern.match(/^((0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/))
            {
                alert("The phone number is not in the correct format! Please re-enter Such as:0321-4816048");
                $("#"+phone).val("");
                $("#"+phone).focus();
            }
        }
    }
    // 验证身份证 
    function isCardNo(phone) {
        var identity=document.getElementById("identitySourceId").value;
        var pattern=document.getElementById(phone).value;
        if(identity==""){
            if(pattern!=""){
                alert("Please select the document type first");
                $("#"+phone).val("");
                $("#identitySourceId").focus();
            }
        }else{
            if(pattern!="" && identity=="1"){
                if(!pattern.match(/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/))
                {
                    alert("The ID card is not in the correct format! Please re-enter");
                    $("#"+phone).val("");
                    $("#"+phone).focus();
                    return false;
                }
            }
        }
    }
    // 验证中文名称
    function isChinaName(phone) {
        var pattern=document.getElementById(phone).value;
        if(pattern!=""){
            if(!pattern.match(/^[\u4E00-\u9FA5]{1,6}$/))
            {
                alert("The input is not in Chinese. Please enter chinese.");
                $("#"+phone).val("");
                $("#"+phone).focus();
            }
        }
    }
    //只能为整数或者两位小数
    if(amount != "" && amount != null){
        if (!(/^\d+(\.\d{1,2})?$/.test(amount))) {
            alert("Billable Amount 只能为整数或者两位小数");
            $("#billableAmount").val("");
            $("#billableAmount").focus();
            return false;
        }
    }

    //格式化为0,验证填入时间不能为负数,验证填入时间必须为0.5的倍数
    function Initialization(a,b){
        //格式化为0
        if(document.getElementById(a).value==""){
            $("#"+a).val(0);
            return false;
        }
        //验证填入时间不能为负数
        if(document.getElementById(a).value<0){
            alert("Please fill in the correct number of hours (not negative)");
            $("#"+a).focus();
            $("#"+a).val("");
            return false;
        }
        //验证填入时间必须为0.5的倍数
        var chack = /^\d*(\.(5|0))?$/;
        if(!chack.test($("#"+a).val())){
            alert(b+" Data must be a multiple of 0.5");
            $("#"+a).focus();
            $("#"+a).val("");
            return false;
        }
        
    }
</script>


 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值