Skip to content

Instantly share code, notes, and snippets.

@andrewjamesford
Created June 6, 2012 03:38
Show Gist options
  • Save andrewjamesford/2879742 to your computer and use it in GitHub Desktop.
Save andrewjamesford/2879742 to your computer and use it in GitHub Desktop.
Time validation in ASP.Net MVC using a regular expression
[DisplayFormat(ApplyFormatInEditMode = true,DataFormatString = "{0:HH:mm}")]
[RegularExpression(@"^(?:0?[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$", ErrorMessage = "Invalid time.")]
public DateTime? YourDateTime { get; set; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment