Allow only numbers in textbox using JavaScript

<html>
<head>
<title>Allow only numbers in textbox using JavaScript</title>
<script language="Javascript" type="text/javascript">
function onlyNumber(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>
</head>
<body>
<table>
<tr>
<td>
<input type="text" onkeypress="return onlyNumber(event,this);" />
</td>
</tr>
</table>
</body>
</html>
Advertisements
Categories: PHP & Joomla | Tags: , , , , | Leave a comment

Post navigation

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: