时间可以为空,或者是>=今天的时间

解决方案 »

  1.   

    后台验证是否大于等于今天吧...if(TextBox1.Text.Trim() != "")
    {
       if((Convert.ToDateTime(TextBox1.Text.Trim()) - DateTime.Now).Days >= 0)
       //...
    }
      

  2.   

    如果Text非时间格式.不就死翘翘了...
    还是同意#3的.用js来搞定...
      

  3.   

    嗯,可以用DateTime.TryParse 
      

  4.   

    代码如下(.aspx):
    <asp:TextBox ID="txtP24DateScheduledInterview" runat="server" onkeypress="return noenter();"></asp:TextBox>
                <asp:Image ID="imgP24DateScheduledInterview" runat="server" ImageUrl="Images/calender.jpg" />
                <cc1:CalendarExtender ID="ceP24DateScheduledInterview" runat="server" TargetControlID="txtP24DateScheduledInterview" 
                Format="yyyy-MM-dd" PopupButtonID="imgP24DateScheduledInterview" FirstDayOfWeek="Default" >
                </cc1:CalendarExtender>   
                <asp:RegularExpressionValidator ID="revP24DateScheduledInterview" runat="server" 
                ErrorMessage="Sorry, wrong type <b>yyyy-mm-dd</b>" 
                ValidationExpression="^\d{4}-([0][1-9]|[1][012])-([0][1-9]|[12][0-9]|[3][01])$"
                ControlToValidate="txtP24DateScheduledInterview" 
                Display="None" >
                </asp:RegularExpressionValidator>  
                <cc1:ValidatorCalloutExtender ID="vceP24DateScheduledInterview" runat="server" TargetControlID="revP24DateScheduledInterview" HighlightCssClass="css" Width="320px">
                </cc1:ValidatorCalloutExtender>
    这个正则只验证时间。
      

  5.   

    为空可以验证
    大于今天
    TimeSpan ts=DateTime.Parse("")-DateTime.Now;
    temp=document.getElementById("TextBox1").value.split("-");
       dt1 = new Date(parseInt(temp[0],10), parseInt(temp[1],10),parseInt(temp[2],10),0,0,0); 
       dt2 = new Date();                                                                     //今天
       dt3 = new Date(dt2.getFullYear(),dt2.getMonth()+1,dt2.getDate()+1,0,0,0);                  
       iii = parseInt(Date.parse(dt3.toGMTString()))-parseInt(Date.parse(dt1.toGMTString()));
          
        if(iii>0)
        {
            alert("已经过期!");        
          }
      

  6.   

    用CompareValidator验证控件可以!
    设置一个TextBox2,隐藏,赋今天的值,TextBox1和TextBox2比较即可!代码如下:
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:CompareValidator ID="CompareValidator1" runat="server" 
            ControlToCompare="TextBox2" ControlToValidate="TextBox1" 
            ErrorMessage="必须大于或等于今天的日期" Operator="GreaterThanEqual" Type="Date">*</asp:CompareValidator>
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
        <asp:Button ID="Button1" runat="server" Text="Button" />
        <asp:TextBox ID="TextBox2" runat="server"  style="display:none;"></asp:TextBox>
    后台对TextBox2赋今天的值:
        protected void Page_Load(object sender, EventArgs e)
        {
            TextBox2.Text = DateTime.Today.ToShortDateString();
        }