Monday, June 8, 2009

Using regular expression for the time format validation

public bool IsValidTime(string thetime)
{
string reg=@"([0-1]\d|2[0-3]):([0-5]\d)";
Regex checktime = new Regex(@reg);

//Regex checktime = new Regex(@"^(20|21|22|23|[01]d|d)(([:][0-5]d){1,2})$");

return checktime.IsMatch(thetime);
}

No comments: