How to write a regular expression which contain format like 00:00
the 00 before : must be digit between 0-24 and 00 after : must be digit between 0-59
i have my code below but somehow some it cannot work properly.
[RegularExpression(@"[0-24]+:[0-59]", ErrorMessage = "Format was invalid")]
For Exmaple
00:59 was accepted
25:60 was not accepted
What about something simple like this?
It matches on any time from
00:00to23:59. Note that it does not need the leading zero as written, so will also accept times like7:00or7:3for three minutes past seven (this is consistent with how you asked your question).If you want it to require the leading zeros, just remove the question marks…