English 中文(简体)
J Query Valid
原标题:JQuery Validation

我试图拿我的表格来验证......基本上来说,它的工作效果不大,但我有两个文字箱,一个是起始日期,另一个是以毫米/d/yyyyyyy格式结束的日期。

if the start date is greater than the end date...there is an error if the end date is less than the start date...there is an error if the start date is less than today s date...there is an error

唯一一件事是在我纠正错误时,错误警告仍然存在。

    dates.change(function () {
        var testDate = $(this).val();
        var otherDate = dates.not(this).val();
        var now = new Date();
        now.setHours(0, 0, 0, 0);

        // Pass Dates
        if (testDate !=    && new Date(testDate) < now) {
            addError($(this));
            $( .flightDateError ).text( * Dates cannot be earlier than today. );
            isValid = false;
            return;
        }

        // Required Text 
        if ($(this).hasClass("FromCal") && testDate ==   ) {
            addError($(this));
            $( .flightDateError ).text( * Required );
            isValid = false;
            return;
        }
        // Validate Date
        if (!isValidDate(testDate)) {
            // $(this).addClass( validation_error_input );  
            addError($(this));
            $( .flightDateError ).text( * Invalid Date );
            isValid = false;
            return;
        }
        else {
            // $(this).removeClass( validation_error_input );
            removeError($(this));
            if (!dates.not(this).hasClass( validation_error_input ))
                $( .flightDateError ).text(   );
        }

        // Validate Date Ranges
        if ($(this).val() !=    && dates.not(this).val !=   ) {
            if ($(this).hasClass("FromCal")) {
                if (new Date(testDate) > new Date(otherDate)) {
                    addError($(this));
                    $( .flightDateError ).text( * Start date must be earlier than end date. );
                    isValid = false;
                    return;
                }
            }
            else{
                if (new Date(testDate) < new Date(otherDate)) {
                    addError($(this));
                    $( .flightDateError ).text( * End date must be later than start date. );
                    return;
                }
            }
        }
    });

主要问题是这一部分,我认为,

 // Validate Date Ranges
            if ($(this).val() !=    && dates.not(this).val !=   ) {
                if ($(this).hasClass("FromCal")) {
                    if (new Date(testDate) > new Date(otherDate)) {
                        addError($(this));
                        $( .flightDateError ).text( * Start date must be earlier than end date. );
                        isValid = false;
                        return;
                    }
                }
                else{
                    if (new Date(testDate) < new Date(otherDate)) {
                        addError($(this));
                        $( .flightDateError ).text( * End date must be later than start date. );
                        return;
                    }
                }
            }

testDate is the start date
otherDate is the end date

这里是两个投入箱的C#。

    <div id="campaign_start" style="display: inline-block">
                    <label class="date_range_label">from:</label>  
                    <asp:TextBox ID="FromCalTbx" runat="server" Width="100px" CssClass="FromCal editable float_left required" />
                  </div>
                  <div id="campaign_end" style="display: inline-block">
                    <label class="date_range_label">to:</label>
                    <asp:TextBox ID="ToCalTbx" runat="server" Width="100px" CssClass="float_left optional"/>
</div>
问题回答

你正在用同样方法测试这两个日期,但需要不同的结果。 看像“从Cal”类一样,在这方面非常重要;你能否显示某种超文本,以更清楚地说明它做了哪些工作,以及挑选日期如何运作? (关于答复,我认为,我的声誉使我无法评论)





相关问题
Bind Button.IsEnabled to custom validation with XAML?

I am sorry I didn t know how to title my question any better, you name it if you got a good 1. I have an entity Contact. this person has navigation properties: Address, Phones (A collection of Phone)....

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

Wpf Combobox Limit to List

We are using Wpf Combobox to allow the user to do the following things: 1) select items by typing in the first few characters 2) auto complete the entry by filtering the list 3) suggesting the first ...

Rails 101 | validates_currency?

I ve searched high and low, but I could not find a solution, to what I think seems like a very common task. In a form I want to have a text input that accepts currency strings (i.e. $1,000,000 or ...

CodeIgniter form verification and class

I m using the form validation library and have something like this in the view <p> <label for="NAME">Name <span class="required">*</span></label> <?...

热门标签