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
JavaScript Function for Add only Number in Textbox
Malvik Bhavsar
Dec 29
2015
Code
1.2
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
<
input
type
=
"text"
id
=
"contactno"
name
=
"contactno"
maxlength
=
"10"
,
onkeypress
=
"return onlyNos(event,this);"
>
<
script
language
=
"JavaScript"
>
function onlyNos(e, t) {
try {
if (window.event) {
var
charCode
=
window
.event.keyCode;
}
else if (e) {
var
charCode
= e.which;
}
else { return true; }
if (charCode
>
31 && (charCode
<
48
|| charCode
>
57)) {
return false;
}
return true;
}
catch (err) {
alert(err.Description);
}
}
</
script
>
add only number in texbox
javascript keypress event