I am new in C#.net. I want a validation for textbox which take only hh:mm:ss format. Below is my code and its wroking. It gives output true 23:45:45 (example only) and also true for -23:45:45 (example only). Now I want validation which return false for -23:45:45 (example only) because it is negative time. My running code does not work for negative time.
IsTrue = ValidateTime(txtTime.Text);
if (!IsTrue)
{
strErrorMsg += "\nPlease insert valid alpha time in hh:mm:ss formats";
isValidate = false;
}
public bool ValidateTime(string time)
{
try
{
Regex regExp = new Regex(@"(([0-1][0-9])|([2][0-3])):([0-5][0-9]):([0-5][0-9])");
return regExp.IsMatch(time);
}
catch (Exception ex)
{
throw ex;
}
}