C# Regular Expression to validate a date?

后端 未结 10 1655
后悔当初
后悔当初 2020-12-30 04:45

I am trying to validate a date entered into a text box. There is an input mask on the textbox which forces input of xx/xx/xxxx. I am trying to use a regular expression valid

10条回答
  •  醉梦人生
    2020-12-30 05:38

    You can use DateTime.TryParseExact:

    DateTime dt;
    
    bool isValid = DateTime.TryParseExact(
        "08/30/2009",
        "MM/dd/yyyy",
        CultureInfo.InvariantCulture,
        DateTimeStyles.None,
        out dt);
    

提交回复
热议问题