TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Shaksham Singh
NA
17
6.1k
Utc Validaton using regular expression
Apr 2 2018 5:34 AM
Hello guys,
I have come up with a scenario where I want to validate a textbox with UTC format:
e.g: +05:30 -01:05 (this can be any time format)
I need to validate my textbox strictly, the user must be forced to enter 2 digits after + or minus sign and 2 digits after the colon.
Validation:
1) 1st character must be + or - only
2)next accept only 2 digits then append colon then 2 digits after colon.
Can anybody tell me how do i validate this utc format:
so far i have done this:
<%@ Page Language=
"C#"
AutoEventWireup=
"true"
CodeBehind=
"home.aspx.cs"
Inherits=
"reg.home"
%>
<!DOCTYPE html>
<html xmlns=
"http://www.w3.org/1999/xhtml"
>
<head runat=
"server"
>
<title></title>
<script src=
"scripts/jquery-3.3.1.js"
></script>
</head>
<body>
<form id=
"form1"
runat=
"server"
>
<div>
<asp:TextBox ID=
"TextBox1"
runat=
"server"
onkeyup=
"sayKeyCode(event,this.value);"
>
</asp:TextBox>
</div>
<asp:RegularExpressionValidator ID=
"rgx"
ControlToValidate=
"TextBox1"
runat=
"server"
ErrorMessage=
"only 2 digit is allowed before and after colon"
ForeColor=
"Red"
Display=
"Dynamic"
ValidationExpression=
"^[0-9]{0,9}(\:[0-9]{2,2})?$"
></asp:RegularExpressionValidator>
</form>
<script type=
"text/javascript"
language=
"javascript"
>
function
sayKeyCode(event, v)
{
var
TextBox = document.getElementById(
'<%=TextBox1.ClientID%>'
);
//alert(event.keyCode);
if
(event.keyCode != 8)
{
if
(TextBox.value.length == 2 && TextBox.value.length != 3)
{
TextBox.value = TextBox.value +
":"
;
}
else
{
TextBox.value = TextBox.value;
}
}
}
</script>
</body>
</html>
Reply
Answers (
1
)
crystal reports is not displaying data
How to show pagination according to total row count in lates