本文介绍了始终进行验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从日期起进行验证不应该大于日期.
请帮助我做到这一点.

how to validate from date should not be greater than to date.
plz help me to do it.

推荐答案

function CompareDate()
{
    var From = document.getElementById("TextBoxofFrom").value;
    var To = document.getElementById("TextBoxofTo").value;
    var strSplitFrom = From.split('/')
    var myDateFrom = new Date();
    myDateFrom.setFullYear(strSplitFrom[2], strSplitFrom[1] - 1, strSplitFrom[0]);
    var strSplitTo = To.split('/')
    var myDateTo = new Date();
    myDateTo.setFullYear(strSplitTo[2], strSplitTo[1] - 1, strSplitTo[0]);
    if (myDateFrom > myDateTo) {
        alert("Start date can not greater than End date.");        
        return false;
    }
    else {
        return true;
    }
}


<asp:textbox id="TextBox1" runat="server" xmlns:asp="#unknown"></asp:textbox>
    <asp:calendar id="cal1" runat="server" backcolor="White" bordercolor="Black" xmlns:asp="#unknown">
        BorderStyle="Solid" CellSpacing="1" Font-Names="Verdana" Font-Size="9pt" 
        ForeColor="Black" Height="250px" NextPrevFormat="ShortMonth" 
        onselectionchanged="Calendar1_SelectionChanged" Width="330px">
        <dayheaderstyle font-bold="True" font-size="8pt" forecolor="#333333">
            Height="8pt" />
        <daystyle backcolor="#CCCCCC" />
        <nextprevstyle font-bold="True" font-size="8pt" forecolor="White" />
        <othermonthdaystyle forecolor="#999999" />
        <selecteddaystyle backcolor="#333399" forecolor="White" />
        <titlestyle backcolor="#333399" borderstyle="Solid" font-bold="True">
            Font-Size="12pt" ForeColor="White" Height="12pt" />
        <todaydaystyle backcolor="#999999" forecolor="White" />
    </titlestyle></dayheaderstyle></asp:calendar>
    <asp:textbox id="TextBox2" runat="server" xmlns:asp="#unknown"></asp:textbox>
    <br />
    <asp:calendar id="cal2" runat="server" backcolor="White" bordercolor="Black" xmlns:asp="#unknown">
        BorderStyle="Solid" CellSpacing="1" Font-Names="Verdana" Font-Size="9pt" 
        ForeColor="Black" Height="250px" NextPrevFormat="ShortMonth" 
        onselectionchanged="Calendar2_SelectionChanged" Width="330px">
        <dayheaderstyle font-bold="True" font-size="8pt" forecolor="#333333">
            Height="8pt" />
        <daystyle backcolor="#CCCCCC" />
        <nextprevstyle font-bold="True" font-size="8pt" forecolor="White" />
        <othermonthdaystyle forecolor="#999999" />
        <selecteddaystyle backcolor="#333399" forecolor="White" />
        <titlestyle backcolor="#333399" borderstyle="Solid" font-bold="True">
            Font-Size="12pt" ForeColor="White" Height="12pt" />
        <todaydaystyle backcolor="#999999" forecolor="White" />  </titlestyle></dayheaderstyle></asp:calendar>




受保护的void Calendar1_SelectionChanged(object sender,EventArgs e)
{
DateTime t1 = cal1.SelectedDate;
TextBox1.Text = t1.ToString("dd/MM/yyyy");
}

受保护的void Calendar2_SelectionChanged(object sender,EventArgs e)
{
日历c =新Calendar();
c.SelectedDate = cal1.SelectedDate;
DateTime t2 = cal2.SelectedDate;
如果(c.SelectedDate> t2)
{
Page.ClientScript.RegisterStartupScript(GetType(),"popup","alert(" Invalid Date..Please select date after"+ c.SelectedDate +"'');,true);
}
其他
{
TextBox2.Text = t2.ToString("dd/MM/yyyy");
}
}




protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
DateTime t1 = cal1.SelectedDate;
TextBox1.Text = t1.ToString("dd/MM/yyyy");
}

protected void Calendar2_SelectionChanged(object sender, EventArgs e)
{
Calendar c = new Calendar();
c.SelectedDate = cal1.SelectedDate;
DateTime t2 =cal2.SelectedDate;
if (c.SelectedDate > t2)
{
Page.ClientScript.RegisterStartupScript(GetType(), "popup", "alert(''Invalid Date..Please Select date after"+c.SelectedDate+"'');", true);
}
else
{
TextBox2.Text = t2.ToString("dd/MM/yyyy");
}
}


这篇关于始终进行验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 18:22