none
Validate asp Textbox in Time format(HH:mm:ss)

    Question

  • I have a asp:textbox ,in which user enters Time in hh:mm:ss format.I need to validate the textbox if the user has entered time in the hh:mm:ss format in C#.Please if some one can help me ?
    Monday, September 21, 2009 1:20 AM

Answers

  • You can use (([0-1][0-9])|([2][0-3])):([0-5][0-9]):([0-5][0-9]) regex

           public bool ValidateTime(string time)
            {
                Regex regExp = new Regex(@"(([0-1][0-9])|([2][0-3])):([0-5][0-9]):([0-5][0-9])");
    
                return regExp.IsMatch(time);
            }
    • Proposed as answer by Tamer Oz Monday, September 21, 2009 7:38 AM
    • Marked as answer by YiChun Chen Wednesday, September 23, 2009 8:46 AM
    Monday, September 21, 2009 1:43 AM