MVC validation, Regular expression for a rounded hour
I would like to implement a validation of a property using the RegularExpression attribute to check if the time entered by the user is rounded to the nearest quarter hour (02:15, 02:00,02:45, 02:30 match but not 02:12).
I tried the following one, but it doesn't work.
[Regu开发者_开发知识库larExpression("([0-1][0-9]|[2][0-3]):(([0][0])|([1][5]|[3][0]|[4][5]))]
public DateTime StartHour { get; set; }
Could anyone help me?
Thanks in advance and sorry for my bad English.
([01][0-9]|[2][0-3]):(00|15|30|45)
should work.
^([01][0-9]|2[0-3]):(00|15|30|45)$
should work; ^
= start of string ([01][0-9]|2[0-3])
= (0 or 1 followed by 0-9) or 2 followed by 0-3 a literal colon followed by one of 00, 15, 30 or 45 $
= end of string
精彩评论