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

js简单校验form表单

时间:2018-03-21 15:02:59      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:form   each   log   格式   form表单   简单   def   [1]   邮箱   

/**
 * 数据简单校验
 */
function checkData (formId) {
    var check = true;
    var emailReg = new RegExp("^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$"); //验证邮箱
    var phoneReg = /^[1][3,4,5,7,8][0-9]{9}$/;
    $("#"+formId+" input[type!=‘radio‘]").each(function () {
        if($(this).val() == "" || $(this).val() == null || $(this).val() == undefined) {
            layer.tips(‘不能为空‘, ‘#‘+$(this).attr("id"), {
                tips : [ 2, ‘#ffcc00‘ ],
                time:1000
            });
            check = false;
            return false;
        }else if($(this).attr("name") == "email") {
            if(!emailReg.test($(this).val())) {
                layer.tips(‘邮箱格式不正确‘, ‘#‘+$(this).attr("id"), {
                    tips : [ 2, ‘#ffcc00‘ ],
                    time:1000
                });
                check = false;
                return false;
            }
        }else if($(this).attr("name") == "phone") {
            if(!phoneReg.test($(this).val())) {
                layer.tips(‘手机格式不正确‘, ‘#‘+$(this).attr("id"), {
                    tips : [ 2, ‘#ffcc00‘ ],
                    time:1000
                });
                check = false;
                return false;
            }
        }
    })
        return check;
}

 

js简单校验form表单

标签:form   each   log   格式   form表单   简单   def   [1]   邮箱   

原文地址:https://www.cnblogs.com/Amaris-Lin/p/8616809.html

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