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
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Check the validation which allows only didgits & hyphen
Ghanashyam Nayak
Apr 29, 2020
58.1
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
Using javascript it will check the user's input & allow only digits 7 hyphen.
<html>
<head>
<title>Sample Code</title>
<script type=
"text/javascript"
>
function
Check(b)
{
var
a = /(^[0-9]+[-]*[0-9]+$)/;
if
(a.test(b) ==
true
)
{
alert(
"Match Criteria"
)
}
else
{
alert(
"Please Enter Only Digits & Hyphen."
)
}
};
</script>
</head>
<body bgcolor=#00ff00 alink=blue vlink=blue>
<FORM name=
"windowEvent"
>
Number : <input type=
"text"
name=
"txtnumber"
/>
<input type=
"button"
value=
"Check"
name=
"btnNumber"
onClick=
"Check(txtnumber.value)"
/>
</FORM>
</body>
</html>
Check the validation which allows only didgits hyphen
Next Recommended Reading
Allow Only Numeric Values and allow Only one DOT in TEXTBOX using JavaScript