Sreenish

Sreenish

  • NA
  • 249
  • 33.3k

how to validate 12 hr and 24 hr format in one textbox

Aug 6 2015 8:06 AM
i have to validate a time in a textbox  in 12 hr and 24 hr format...for that i have two checkboxes like 12 hr and 24 hr if i checked 12 hr then that textbox should accept only 12 hr format if i checked 24 hr only 24 hr format should accept how to do this???
 
am sharing what i tried...
 
Source::
 
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="12time.aspx.cs" Inherits="Validators.Validators_Task._12time" %>
<!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>Time 12/24</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtTime" runat="server" >
</asp:TextBox>
<asp:CheckBox ID="CheckBox1" runat="server" Text="12hr" />
<asp:CheckBox ID="CheckBox2" runat="server" Text="24hr" />
<asp:RegularExpressionValidator ID="rev" runat="server" ErrorMessage="InvalidTime"
ControlToValidate="txtTime" ValidationExpression="^(1[0-2]|0[1-9]):[0-5][0-9]\040(AM|am|PM|pm)$">
</asp:RegularExpressionValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="InvalidTime"
ControlToValidate="txtTime" ValidationExpression="^([01]?[0-9]|2[0-3]):[0-5][0-9]$">
</asp:RegularExpressionValidator>
</div>
</form>
</body>
</html>
in code behind have no idea how to implement my requirement...any answers appreciated .

Answers (2)