我正在使用dd/MM/yyyy格式输入日期,我需要使用/分隔符来验证日期月份年,我想使用比较验证器来实现..plz帮助我 [英] i'm using the dd/MM/yyyy format for the date entry and i need to Validate date month year with / separator i want to do that with compare validator..plz help me

查看:109
本文介绍了我正在使用dd/MM/yyyy格式输入日期,我需要使用/分隔符来验证日期月份年,我想使用比较验证器来实现..plz帮助我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

i''m使用dd/MM/yyyy格式输入日期,我需要使用/分隔符来验证日期月份年,我想使用比较验证器来做到这一点..plz帮助我

i''m using the dd/MM/yyyy format for the date entry and i need to Validate date month year with / separator i want to do that with compare validator..plz help me

推荐答案

如果您只需要验证日期的格式,则使用正则表达式.

如果您需要针对特定​​日期进行验证,则最好使用自定义验证程序,因为输入的日期可以采用不同的格式,例如一个或两位数的月份.
If you just need to validate the format of the date then use a Regular Expression.

If you need to validate against a specific date then using a custom validator would be better since the date entered could be in different format, such as one or two digit month.


请参阅此链接

它具有您所要求的解决方案..

http://geekswithblogs.net/ptahiliani/archive/2009/07/04/how-to-use-compare-validator-with-ddmmyyyyy-format-of-date.aspx
Refer this link

It has the excat solution you are asking for..

http://geekswithblogs.net/ptahiliani/archive/2009/07/04/how-to-use-compare-validator-with-ddmmyyyy-format-of-date.aspx

The converted code from vb to c#

Protected Page_Load(object sender, System.EventArgs e) 
    {
        cmpStartDate.ValueToCompare =    System.DateTime.Now.ToShortDateString();
    }
    
Protected btnValidate_Click(object sender, System.EventArgs e) 
    {
        if (!Page.IsValid)
            Response.Write("Valid dates entered");
        
    }


这篇关于我正在使用dd/MM/yyyy格式输入日期,我需要使用/分隔符来验证日期月份年,我想使用比较验证器来实现..plz帮助我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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