How to validate time using Regular Expression

How to validate time using Regular Expression


In this article we will discuss "How to validate time(00:00:00) using Regular Expression".

1)Just open new web application project.
2)Just drag and drop one text box,button control to your new web page.
3)drag and drop one "RegularExpressionValidator"
4)set ValidationExpression equal to "^[\d]{2}[:][\d]{2}[:][\d]{2}$"
5)set ControlToValidate="TextBox1"
6)set ErrorMessage="enter valid time format"

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="LoginControl" Namespace="LoginControl" TagPrefix="cc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
<head runat="server">
<title>Untitled Page</title>
<form id="form1" runat="server">

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="TextBox1" ErrorMessage="enter valid time format"
<asp:Button ID="Button1" runat="server" Text="Button" ValidationGroup="a" />



No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: