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

前端 未结 7 938
粉色の甜心
粉色の甜心 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:38

    For client-side (JavaScript) validation, you can use

    ^\d\d/\d\d/\d\d \d\d:\d\d:\d\d [AP]M$
    

    which will check syntax (digits, spaces, separators), strictly, against your spec. If a match is obtained, you then need to check the ranges of the values entered (e.g. 1 <= month <= 12, etc.) in the subgroups for the returned match.

    Use this site to test out the regex.

提交回复
热议问题