码迷,mamicode.com
首页 > Web开发 > 详细

js 常用验证

时间:2014-05-08 12:45:49      阅读:395      评论:0      收藏:0      [点我收藏+]

标签:c   cti   js   a   test   mat   

邮箱验证:

 

 

 $(function () {
            $("#txt_Email").blur(function () {
                var email = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
                var str = $("#txt_Email").val();
                if (email.test(str) == false) {
                    alert(‘对不起,请输入正确的邮箱!‘);
                    return;
                }
            });
        });

 

 

 

各种证件号验证:

 

 

 

 

    $("#txt_IdCard").blur(function () {
                var officer = /\d{8}/;
                var Idcard = /(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$)|(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)/;
                var huzhao = /^(P\d{7}|G\d{8}|S\d{7,8}|D\d+|1[4,5]\d{7})$/;
                var taibaozheng = /^[a-zA-Z]([0-9]\d{9})$/;
                var gangaotongxingzheng = /\d{9}/;
                var str = $("#txt_IdCard").val();
                if ($("#drop_Card").val() == "身份证") {
                    var r = str.match(Idcard);
                    if (Idcard.test(str) == false) {
                        alert(‘对不起,您输入的身份证证件号不正确!‘);
                        return;
                    }
                    var birthday = $(this).val().substr(6, 4) + "-" + $(this).val().substr(10, 2) + "-" + $(this).val().substr(12, 2);
                    $("#txt_Birth").val(birthday);
                }
                else if ($("#drop_Card").val() == "军官证") {
                    if (officer.test(str) == false) {
                        alert(‘对不起,您输入的军官证证件号不正确!‘);
                        return;
                    }
                }
                else if ($("#drop_Card").val() == "港澳通行证") {
                    if (gangaotongxingzheng.test(str) == false) {
                        alert(‘对不起,您输入的港澳通行证证件号不正确!‘);
                        return;
                    }
                }
                else if ($("#drop_Card").val() == "台胞证") {
                    if (taibaozheng.test(str) == false) {
                        alert(‘对不起,您输入的台胞证证件号不正确!‘);
                        return;
                    }
                }
                else if ($("#drop_Card").val() == "护照") {
                    if (huzhao.test(str) == false) {
                        alert(‘对不起,您输入的护照证件号不正确!‘);
                        return;
                    }
                }
            })
            showShangChao();
        });

js 常用验证,布布扣,bubuko.com

js 常用验证

标签:c   cti   js   a   test   mat   

原文地址:http://www.cnblogs.com/haofaner/p/3714035.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!