本文介绍了出生日期应为DD-MM-YYYY格式,出生日期不应为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我需要使用正则表达式验证DateOfBirth。

哪个完整填写以下条件

出生日期应该是DD-MM-YYYY格式(如12-12-2014等),出生日期不应该是未来日期

任何人请帮助我

Hi,
I need to validate the DateOfBirth using regular Expression.
Which full fill the below condition together
Date of Birth should be in DD-MM-YYYY format (like 12-12-2014 etc) and date of birth should not be future date
Any one please help me

推荐答案

DateTime dtBirth;
if (DateTime.TryParseExact(input, "dd-MM-yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out dtBirth))
    {
    if (dtBirth < DateTime.Now.Date)
        {
        ...
        }
    }


string input ="12-12-2014";
DateTime dt;
if (DateTime.TryParseExact( input, "dd-MM-yyyy",CultureInfo.InvariantCulture,DateTimeStyles.None, out dt)
        && dt < DateTime.Now)
{
    //validation success
}



这篇关于出生日期应为DD-MM-YYYY格式,出生日期不应为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-26 06:02