2
Answers

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

Sreenish

Sreenish

9y
1k
1
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)
1
Amit Singh

Amit Singh

NA 3.7k 46.6k 9y
1.First Create on Website
 
2.Add one Master Page
 
3.Add One WebForm and add with Master Page
 
4.Create one Css page
 
https://www.asp.net/web-forms/overview/older-versions-getting-started/master-pages/creating-a-site-wide-layout-using-master-pages-cs
 
http://www.aspdotnet-suresh.com/2014/07/master-page-with-menu-control-in-aspnet-example.html 
 
 
0
Raja

Raja

NA 1.7k 45.3k 9y
Give some extensive explain sir.
0
Amit Singh

Amit Singh

NA 3.7k 46.6k 9y
Add external  CSS  to Master page
 
<link href="MyStyle.css" rel="stylesheet" type="text/css"> in head tag.
 
 
<asp:Textbox id="Textbox1" runat="server" CssClass="your class/id name">