我试图拿我的表格来验证......基本上来说,它的工作效果不大,但我有两个文字箱,一个是起始日期,另一个是以毫米/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>