formValidator的一些验证实例
web jQuery 2018-12-27 1703 0
关于本站

“最难不过坚持”

本人承接扒站仿站,php网站维护,病毒查杀,网站编辑,网站改版,html制作

有需要网站维护,改版,病毒查杀,网站编辑,网站备案,html制作等相关的工作可以联系我。
本人有多年相关工作经验,也可提供免费咨询,交个朋友。
有需要探讨问题的朋友,也可以加我微信,共同探讨!
微信:15011482830 QQ:408917339

6447907 2613 39
最新评论
https://jueru.net/
评 留言
:weixiao:
评 留言
:shuijiao: :weiqu: :zhenbang: :leng:
评 留言
:yiwen: :yiwen: :yiwen: :yiwen:
评 EasySass: could not generate CSS file. See Output panel for details.
这个业务逻辑多少都有点奇怪了,阅读浏览次数增值在新闻详情页的控制器方法里setInc,这怎么还写进模型事件里了。如果非要用onAfterRead也可以,把新闻文章的内容单独分出来一个news_content表,然后把它和news做关联,然后给news_content表的onAfterRead事件做增值处理,这样点进新闻页内查询到文章内容时才会触发它。
评 TP6模型事件-查询后onAfterRead不好用
文章标签更多
ThinkPHP (254)
Mysql (58)
DedeCms (33)
jQuery (67)
证件照 (1)
setInc (4)
setDec (4)
onclick (5)
打开边栏(ESC) 关闭边栏(ESC)
$(function () {
    try {
        $.formValidator.initConfig({
            formid: "formTable",
            errorfocus: false,
            submitonce: true,
            tipstyle: "both",
            onerror: function () { // 验证不通过时的回调函数
                alert("红色提示处输入非法,请根据提示修改!");
            }
        });
        //验证字符串(必填)
        $("#name").formValidator({ // 验证:模块名称
            onshow: "(必填)",
            onfocus: "(必填)不超过50个字符",
            oncorrect: "(正确)"
        }).inputValidator({
            min: 1,
            max: 50,
            onerrormin: "(错误)不能为空",
            onerrormax: "(错误)不超过50个字符,汉字算两个字符"
        });

        //验证字符串(选填)
        $("#name").formValidator({ // 验证:模块名称
            onshow: "(选填)",
            onfocus: "(选填)不超过50个字符",
            oncorrect: "(正确)",
            empty: true
        }).inputValidator({
            min: 1,
            max: 50,
            onerrormin: "(错误)不能为空",
            onerrormax: "(错误)不超过50个字符,汉字算两个字符"
        });

        //验证时间
        $("#addDate").formValidator({ // 验证:发送时间
            onshow: "(必填)",
            onfocus: "(必填)请选择操作时间",
            oncorrect: "(正确)"
        }).functionValidator({
            fun: function (val, elem) {
                if (!/^\d{4}-\d{2}-\d{2}[ ]\d{2}:\d{2}$/.test(val)) {
                    return "(错误)请选择操作时间";
                }
                return true;
            }
        });

        //ajax验证
        $("#account").formValidator({ // 验证:模块名称
            onshow: "(必填)",
            onfocus: "(必填)不超过50个字符",
            oncorrect: "(正确)"
        }).inputValidator({
            min: 1,
            max: 50,
            onerrormin: "(错误)不能为空",
            onerrormax: "(错误)不超过50个字符,汉字算两个字符"
        }).ajaxValidator({
            type: "post",
            url: "EnterpriseManage!ajaxValidatorUserAccount.action",
            success: function (data) {
                if (data == "0") {
                    return true;
                } else if (data == "1") {
                    return false;
                }
            },
            onerror: "该账号已被占用,请更换!"
        });

        //密码及重复密码验证
        $("#password").formValidator({ // 验证:模块名称
            onshow: "(必填)",
            onfocus: "(必填)不超过11个字符",
            oncorrect: "(正确)"
        }).inputValidator({
            min: 1,
            max: 50,
            onerrormin: "(错误)不能为空",
            onerrormax: "(错误)不超过11个字符,汉字算两个字符"
        });

        $("#passwordRepeat").formValidator({
            onshow: "(必填)",
            onfocus: "(必填)2次密码必须一致",
            oncorrect: "(正确)"
        }).compareValidator({
            desid: "password",
            operateor: "=",
            onerror: "(错误)2次密码不一致,请确认"
        });

        //图片格式验证
        $("#tcCodeLogo").formValidator({
            onshow: "(选填)",
            onfocus: "(选填)请上传图片文件",
            oncorrect: "(正确)",
            empty: true
        }).regexValidator({
            regexp: regexEnum.picture,
            onerror: "只能上传图片文件"
        });

        //数值验证
        $("#nameNum").formValidator({ // 验证:模块名称
            onshow: "(必填)",
            onfocus: "(必填)值1到50",
            oncorrect: "(正确)"
        }).inputValidator({
            min: 1,
            max: 50,
            type: "value",
            onerrormin: "(错误)不能为空",
            onerrormax: "(错误)值1到50"
        });
        //电话验证
        $("#linkPhone").formValidator({
            onshow: "(选填)",
            onfocus: "(选填)",
            oncorrect: "(正确)",
            empty: true
        }).regexValidator({
            regexp: "^(\\d{3,4}-?\\d{7,8}|(13|15|18)\\d{9})$",
            onerror: "(错误)电话号码格式不正确,请检查"
        });

        //EMail验证
        $("#linkEmail").formValidator({
            onshow: "(选填)",
            onfocus: "(选填)请选择正确EMail格式",
            oncorrect: "(正确)",
            empty: true
        }).regexValidator({
            regexp: regexEnum.email,
            onerror: "(错误)Email格式不正确,请检查"
        });

        //select验证
        $("#testSelect").formValidator({
            onshow: "(必填)",
            onfocus: "(必填)请选择选项",
            oncorrect: "(正确)"
        }).inputValidator({
            min: 0,  //开始索引
            onerror: "你是不是忘记选择学历了!"
        });

        //隐藏时,默认验证通过
        $("#smsProductName").formValidator({ // 验证
            onshow: "(必填)",
            onfocus: "(必填)不超过50个字符,汉字算两个字符",
            oncorrect: "(正确)"
        }).functionValidator({
            fun: function (val, elem) {
                if ($("#smsProductName").is(":hidden")) {
                    return true;
                }
                if (!/^\S{1,50}$/.test(val)) {
                    return "(错误)不超过50个字符,汉字算两个字符";
                }
                return true;
            }
        });
        //多选选择框的验证方式 略有点复杂了
        $(":checkbox[name='productType']").formValidator({
            onshow: "(至少选择一个)",
            onfocus: "(至少选择一个)",
            oncorrect: "(正确)"
        }).functionValidator({
            fun: function (val, elem) {
                var objs = $(":checkbox[name='productType']");
                for (var i = 0; i < objs.length; i++) {
                    if ($(objs[i]).attr("checked") == true) {
                        $('#productTypeTip').removeClass();
                        $('#productTypeTip').addClass("onSuccess");
                        $('#productTypeTip').html();
                        $('#productTypeTip').html("<nobr>正确</nobr>");
                        return true;
                    }
                }
                $('#productTypeTip').removeClass();
                $('#productTypeTip').addClass("onError");
                $('#productTypeTip').html();
                $('#productTypeTip').html("<nobr>(至少选择一项)</nobr>");
                return false;
            }
        });
    } catch (e) {
        alert(e);
    }
});

版权声明:本篇文章来源于网络。 来源链接

相关推荐
jquery出现Uncaught TypeError: $(...).prop is not a function问题
jQuery | 2019-08-23 6336
做全选功能的时候用到 var xz = $(this).prop("checked"); 提示: Uncaught TypeError: $(...).prop is not a function 应该是jquery版本过低造成的,更换高版本成功解决问题, jquery下载地址 http://www...
TypeError: e.indexOf is not a function解决方法
jQuery | 2020-06-23 6329
This error might be caused by jquery event aliases like .load, .unload or .error deprecated since jQuery 1.8. Look for these aliases in your code and replace them with .o...
评论:0条
评论加载中...
发表评论