Regular expression for date time format “MM/DD/YY HH:mm:ss AM/PM” in asp.net regular expression validator

前端 未结 7 934
粉色の甜心
粉色の甜心 2020-12-19 15:54

Can anyone tell me the regular expression format for \"MM/DD/YY HH:mm:ss AM/PM\" to use it in a regular expression validator, in asp.net 2.0

7条回答
  •  囚心锁ツ
    2020-12-19 16:45

    Check this one. It also validates leap year.

    ^(((0[13578]|1[02])[\/\.-](0[1-9]|[12]\d|3[01])[\/\.-]((19|[2-9]\d)\d{2})\s(0[0-9]|1[0-2]):(0[0-9]|[1-59]\d):(0[0-9]|[1-59]\d)\s(AM|am|PM|pm))|((0[13456789]|1[012])[\/\.-](0[1-9]|[12]\d|30)[\/\.-]((19|[2-9]\d)\d{2})\s(0[0-9]|1[0-2]):(0[0-9]|[1-59]\d):(0[0-9]|[1-59]\d)\s(AM|am|PM|pm))|((02)[\/\.-](0[1-9]|1\d|2[0-8])[\/\.-]((19|[2-9]\d)\d{2})\s(0[0-9]|1[0-2]):(0[0-9]|[1-59]\d):(0[0-9]|[1-59]\d)\s(AM|am|PM|pm))|((02)[\/\.-](29)[\/\.-]((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))\s(0[0-9]|1[0-2]):(0[0-9]|[1-59]\d):(0[0-9]|[1-59]\d)\s(AM|am|PM|pm)))$
    
    06/12/2014 12:45:56 AM // true
    11-12-1965 06:04:34 PM // true
    11/31/2015 11:40:00 AM // false
    12-31-1945 01:38:09 PM // true
    02/29/2012 09:04:10 AM // true [leap year]
    02/29/2013 09:04:10 AM // false
    06.12.2014 13:04:10 AM // false
    

    Demo

提交回复
热议问题