locked
How to validate dates? RRS feed

  • Question

  • User672081070 posted

    You Could use the validator:

    [RegularExpression(@"^(([0-2]\d|[3][0-1])\/([0]\d|[1][0-2])\/[2][0]\d{2})$|^(([0-2]\d|[3][0-1])\/([0]\d|[1][0-2])\/[2][0]\d{2}\s([0-1]\d|[2][0-3])\:[0-5]\d\:[0-5]\d)$", ErrorMessage = "Not A DateTime")]

     

    hi sjnaughton i need small help what will be the valid dates as per the regex you have given and what are invalid. Can you give some samples

    Saturday, January 21, 2012 5:16 AM

Answers

  • User-330204900 posted

    Hi Dora, the thread you last replied to seems to be locked, what I did was go to RegExLib.com see it here http://www.regexlib.com/Search.aspx?k=date&c=-1&m=-1&ps=20

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, January 22, 2012 10:11 AM
  • User3866881 posted

    Hello Dora743:)

    The mvp's idea is quite nice,it should be ^\d{4}[\-\/\s]?((((0[13578])|(1[02]))[\-\/\s]?(([0-2][0-9])|(3[01])))|(((0[469])|(11))[\-\/\s]?(([0-2][0-9])|(30)))|(02[\-\/\s]?[0-2][0-9]))$

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 26, 2012 9:37 PM

All replies

  • User-330204900 posted

    it's a while ago now I think I just got it from www.regexlib.com

    Saturday, January 21, 2012 10:43 AM
  • User-330204900 posted

    Hi Dora, the thread you last replied to seems to be locked, what I did was go to RegExLib.com see it here http://www.regexlib.com/Search.aspx?k=date&c=-1&m=-1&ps=20

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, January 22, 2012 10:11 AM
  • User3866881 posted

    Hello Dora743:)

    The mvp's idea is quite nice,it should be ^\d{4}[\-\/\s]?((((0[13578])|(1[02]))[\-\/\s]?(([0-2][0-9])|(3[01])))|(((0[469])|(11))[\-\/\s]?(([0-2][0-9])|(30)))|(02[\-\/\s]?[0-2][0-9]))$

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 26, 2012 9:37 PM