How to validate time using Regular Expression
How to validate time using Regular Expression
Abstract
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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="TextBox1" ErrorMessage="enter valid time format"
SetFocusOnError="True"
ValidationExpression="^[\d]{2}[:][\d]{2}[:][\d]{2}$"
ValidationGroup="a"></asp:RegularExpressionValidator>
<asp:Button ID="Button1" runat="server" Text="Button" ValidationGroup="a" />
</form>
</body>
</html>