473,395 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 6620
pshm
20
i think there is no direct properties to control the components like text box
try this javascript it will help you

[HTML]<head>
<script type="text/javascript">
<!--
function acceptOnlyNumbers(id,limit){

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

var value = id.value;
if(value.length >= limit){
event.keyCode=8;
return false;
}

return true;
}
else
event.keyCode=8;
return false;
}
//-->
</script>
</head>
<body>
<input type="text" length=4 id="txtNum" onkeypress="javascript:acceptOnlyNumbers(this,4);" />

</body>[/HTML]

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

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

Similar topics

10
by: nkp | last post by:
Sorry guys, basic questions..... 1)how do you prevent negative numeric input in a text box (-2345 etc) 2)how do detect /prevent input of LESS than 8 characters in a text box( where a password must...
6
by: WindAndWaves | last post by:
Hi Gurus In my quest in putting my first javascript together, I am now trying to conquer something that seems trivial, but has taken me hours. I would like to format a field in a form once the...
7
by: |{evin | last post by:
I'm currently working on what has turned in to something much larger that I wanted it to be. The upside is that I'm getting $$ to do it... but anywho. I currently have textboxes set up to...
3
by: Agnes | last post by:
In textbox, I know I can set e.handled = false in keypressevent , So I can restrict the user to input some invalid character or disallow the user to input any thing Now, in datagrid, there are 3...
1
by: John_H | last post by:
Re: ASP.NET 2.0 I would like suggestions or code examples on how to collect a variable length list of input data (item# & item quantity specifically). I thought that I could accomplish this...
0
by: Anonieko | last post by:
Are there any javascript codes there? Answer: Yes On the PageLoad event call InitialClientControsl as follows /// <summary> /// This will add client-side event handlers for most of the...
1
by: =?Utf-8?B?Qw==?= | last post by:
I want to restrict the user entering nonalphanumeric keys using Javascript onKeypress. One exception is that I want to allow the user to enter spaces. How can I do this? Thanks in Advance.
5
by: Dakrat | last post by:
Allow me to preface this post by saying that this is my first database project, and while I have learned a lot, any concepts I have learned are hit and miss as I have found new requirements and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.