ddMethod(“dateRange”)调用。警报从未出现,因此我假设验证程序从未调用该方法。是的,这基本上就是我在回答自己的问题时所做的。本例中的不同之处在于,我需要检查两个日期,如果两个日期都不为null,则确保结束日期晚于开始日期。 jQuery(

ddMethod(“dateRange”)调用。警报从未出现,因此我假设验证程序从未调用该方法。是的,这基本上就是我在回答自己的问题时所做的。本例中的不同之处在于,我需要检查两个日期,如果两个日期都不为null,则确保结束日期晚于开始日期。 jQuery(,jquery,date,validation,Jquery,Date,Validation,ddMethod(“dateRange”)调用。警报从未出现,因此我假设验证程序从未调用该方法。是的,这基本上就是我在回答自己的问题时所做的。本例中的不同之处在于,我需要检查两个日期,如果两个日期都不为null,则确保结束日期晚于开始日期。 jQuery(document).ready(function() { // a custom method for validating the date range jQuery.validator.addMethod("dateRange", func


ddMethod(“dateRange”)调用。警报从未出现,因此我假设验证程序从未调用该方法。是的,这基本上就是我在回答自己的问题时所做的。本例中的不同之处在于,我需要检查两个日期,如果两个日期都不为null,则确保结束日期晚于开始日期。
jQuery(document).ready(function() {
// a custom method for validating the date range
jQuery.validator.addMethod("dateRange", function() {
    var date1 = new Date(jQuery("#StartDate").val());
    var date2 = new Date(jQuery("#EndDate").val());
    return (date1 < date2);
}, "Please check your dates. The start date must be before the end date.");

// a new class rule to group all three methods
jQuery.validator.addClassRules({
    requiredDateRange: { required: true, date: true, dateRange: true }
});

// overwrite default messages
jQuery.extend(jQuery.validator.messages, {
    required: "These fields are required",
    date: "Please specify valid dates"
});

jQuery("#mainForm").validate({ 
    submitHandler: function() {
        alert("Valid date range.")
    },
    groups: {
        dateRange: "StartDate EndDate"
    },
    rules: {
        "Title": "required",
        "SourceName": "required",
        "Url": "required",
        "FullText": "required",
        "PublicationDate": "required",
        "CategoryCount": {required: true, min: 1}
    },
    messages: {
        "Title": "Please type in a headline.",
        "SourceName": "Please select a source by typing a few letters and selecting from the choices that pop up.",
        "Url": "Please paste or type in a web page link.",
        "FullText": "Please paste in the full text of the source report.",
        "PublicationDate": "Please provide a date of publication.",
        "CategoryCount": "Please specify at least one category."
    }
});

// Capture changes to the list of selected categories by 
// storing the count in a hidden field.
jQuery(".categoryCheckbox").click(function() {
        var count = new Number(jQuery("#CategoryCount").val());
        if (jQuery(this).attr("checked") == true) {
            count = count + 1;
        } else {
            count = count - 1;
        }

        if (count < 0) {
            count = 0
        };

        jQuery("#CategoryCount").val(count);
});
$("#StartDate").datepicker();
$("#EndDate").datepicker();
jQuery(document).ready(function() {
    // a custom method for validating the date range
    jQuery.validator.addMethod("dateRange", function() {
        var date1 = new Date(jQuery("#StartDate").val());
        var date2 = new Date(jQuery("#EndDate").val());
        return (date1 < date2);
    }, "Please check your dates. The start date must be before the end date.");

    jQuery("#mainForm").validate({
        rules: {
            "Title": "required",
            "SourceName": "required",
            "Url": "required",
            "FullText": "required",
            "PublicationDate": "required",
            "SourceName": "required",
            "CategoryCount": { required: true, min: 1 },
            "EndDate": { required: true, date: true, dateRange: true }
        },
        messages: {
            "Title": "Please type in a headline.",
            "SourceName": "Please select a source by typing a few letters and selecting from the choices that pop up.",
            "Url": "Please paste or type in a web page link.",
            "FullText": "Please paste in the full text of the source report.",
            "PublicationDate": "Please provide a date of publication.",
            "SourceName": "Please select a source for this report.<br />",
            "CategoryCount": "Please specify at least one category.",
            "EndDate": "Please check your dates. The start date must be before the end date."
        }
    });

    // Capture changes to the list of selected categories by 
    // storing the count in a hidden field.
    jQuery(".categoryCheckbox").click(function() {
        var count = new Number(jQuery("#CategoryCount").val());
        if (jQuery(this).attr("checked") == true) {
            count = count + 1;
        } else {
            count = count - 1;
        }

        if (count < 0) {
            count = 0
        };

        jQuery("#CategoryCount").val(count);
    });
});
$.validator.addMethod("dateRange", function() {
    var today = new Date();
    var event_date = new Date( $('#event_date').val() );
    if( event_date >= today )
        return true;
    return false;
}, "Please specify a correct date:");
     rules: {
        event_date: { required: true, dateRange: "event_date" },
    },