469,591 Members | 1,820 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,591 developers. It's quick & easy.

Restrict input in textbox to only numbers and restrict length of input

129 100+
Hello friends,
We have seen many textboxes, it is used as date,readonly,text etc... If we want to restrict the textbox with not to enter letters only numbers and one more thing is restrict the letters in textbox to enter 4 letters only. How these r possible? Help me my friends.
Mar 24 '08 #1
3 6368
i think there is no direct properties to control the components like text box
try this javascript it will help you

<script type="text/javascript">
function acceptOnlyNumbers(id,limit){

if(event.keyCode>=48 && event.keyCode<=58){

var value = id.value;
if(value.length >= limit){
return false;

return true;
return false;
<input type="text" length=4 id="txtNum" onkeypress="javascript:acceptOnlyNumbers(this,4);" />


Prakash M.
Mar 24 '08 #2
16,027 Expert Mod 8TB
Please use Use a Good Thread Title for threads started.
Mar 24 '08 #3
16,027 Expert Mod 8TB
Adapt this simple example. For the length restriction, just use the maxlength attribute.
Mar 24 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

10 posts views Thread by nkp | last post: by
6 posts views Thread by WindAndWaves | last post: by
7 posts views Thread by |{evin | last post: by
1 post views Thread by =?Utf-8?B?Qw==?= | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.