By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
462,033 Members | 613 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 462,033 IT Pros & Developers. It's quick & easy.

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

P: 129
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
Share this Question
Share on Google+
3 Replies

P: 20
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

Expert Mod 15k+
P: 16,027
Please use Use a Good Thread Title for threads started.
Mar 24 '08 #3

Expert Mod 15k+
P: 16,027
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.