检查日期验证 [英] checking date validation

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

问题描述

我正在尝试进行日期验证,但我无法执行此操作.我有两个文本框,一个是发布日期,另一个是到期日期.现在,我要进行验证的有效期限应不小于发布日期.

请帮助我.使用JavaScript或asp.net验证控件.....

I am trying to do date validation but i am not able to do this. I have two textbox one is for Posted date and another is expiry date. Now I want to do validation expiry date should not be less than Posted date.

Please help me..Either using Javascript or asp.net validation controls.....

推荐答案

通常,客户端验证更有效.

Normally client side validation is more effective.

function compareDate()
{

var start = document.getElementById('postedtxtboxid').value;
var end = document.getElementById('exptxtboxid').value

var stDate = new Date(start);
var enDate = new Date(end);
var compDate = enDate - stDate;

if(compDate >= 0)
return true;
else
{
alert("Please Enter the correct date");
return false;
}



快乐编码



Happy Coding


阅读以下内容:
Read this one: http://weblogs.asp.net/sahannet/archive/2011/02/01/date-compare-validator-control-asp-net.aspx[^]


您好,

希望这会对您有所帮助.

Hello,

Hope this will help you..

<asp:TextBox ID="txbPostedDate" runat="server" />
<asp:TextBox ID="txExpireDate" runat="server" />
<asp:CustomValidator OnServerValidate="ValidateDates"

    ErrorMessage="Expiry Date Should not be less than posted date" runat="server" />



在处理程序背后的代码中



In the code behind handle the handler

protected void ValidateDates(object sender, ServerValidateEventArgs e)
{
    DateTime expire= DateTime.Parse(txExpireDate.Text);
    DateTime posted= DateTime.Parse(txbPostedDate.Text);

     TimeSpan ts =posted - expire;

    e.IsValid = td.Days>0;
}



谢谢!!!!



Thanks!!!!


这篇关于检查日期验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆