validator 自定义验证

时间:2021-02-17 23:16:19

直接在当前页面写自定义验证规则

$.validator.addMethod("start_time",function(value,element,params){

    var doubles= /([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})/;
    return this.optional(element)||(doubles.test(value));

},"格式举例:2016-12-5 14:24:11");




$().ready(function(){
    $("#single").validate({
        rules :{
            name:"required",
            start_time:{
                start_time:true,
                required:true
            }
        },
        messages:{
            name:"请输入",
            start_time:{
                start_time:"格式举例:2016-12-5 14:24:11",
                required:"请输入,格式举例:2016-12-5 14:24:11"
            }
        }
    });