473,386 Members | 1,712 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,386 software developers and data experts.

javascript for valiadating textbox

hi,
i have to validate a textbox on client side such that it should allow only float and integer values.
pls suggest me in this regard and it would be helpfull if u give me a working example code.


thanks and regards
vijay
May 21 '07 #1
9 5126
dmjpro
2,476 2GB
u can do during runtime .. not after giving the value in the text box.
i mean .. while u r typing some keycode then u can validate.

look at this sample code.

<input type = text onkeypress = validate()>

now the body of validate function is .... (IE specific)

function validate()
{
var point_pressed = event.srcElement.value.indexOf('.') ? true : false;
if((event.keyCode >=48 && event.keyCode <= 57) || (event.keyCode == 9 && !point_pressed))
//Check the point (.) keycode is 9 or anything else.
{
//allow the key_stroke .... (ie.....do nothing)
}
else event.keyCode = 0; //Block the key code.
}
i think u can arrange it.
so try it. ... it ll work.

kind regads.
dmjpro.
May 21 '07 #2
acoder
16,027 Expert Mod 8TB
hi,
i have to validate a textbox on client side such that it should allow only float and integer values.
pls suggest me in this regard and it would be helpfull if u give me a working example code.


thanks and regards
vijay
Consider using regular expressions. The regular expressions for float and integer can be found on this page for example.

If you don't know regular expressions are, I suggest you read up about them.
May 21 '07 #3
acoder
16,027 Expert Mod 8TB
u can do during runtime .. not after giving the value in the text box.
i mean .. while u r typing some keycode then u can validate.

look at this sample code.

<input type = text onkeypress = validate()>

now the body of validate function is .... (IE specific)



i think u can arrange it.
so try it. ... it ll work.

kind regads.
dmjpro.
There are two problems with this:
1. It only works in IE. That is not acceptable anymore.
2. What if someone presses two dots or even more. That's not floating point.
May 21 '07 #4
dmjpro
2,476 2GB
Actually i mentioned eariler ... that it was IE specific.
but these can be done by other browser supported JS.
is not it?????
because i m working in a project that is IE specific.
so .. i m very much familiar with IE only.
recently i m trying to learn cross-browser supported JS.

and cvijaykrishna mentioned that he is looking for Floating Point validation that's why i did it.

ACODER,
sorry for againsting ur reply.

kind regards.
dmjpro.
May 22 '07 #5
acoder
16,027 Expert Mod 8TB
and cvijaykrishna mentioned that he is looking for Floating Point validation that's why i did it.

ACODER,
sorry for againsting ur reply.
No need to apologise. On looking at your code a second time, I can see that you make the check for the floating point, but a regular expression is much better for validation.
May 22 '07 #6
dmjpro
2,476 2GB
yes u r right .... it is better to use API instead of wasting ur valueable time.

kind regards.
dmjpro.
May 22 '07 #7
hey
tnx for those valuable suggestions i got it using regular expression validator.
with regards and thanks
vijay
May 23 '07 #8
acoder
16,027 Expert Mod 8TB
hey
tnx for those valuable suggestions i got it using regular expression validator.
with regards and thanks
vijay
Glad you got it working. Visit again!
May 23 '07 #9
hi,
i have to validate a textbox on client side such that it should allow only float and integer values.
pls suggest me in this regard and it would be helpfull if u give me a working example code.


thanks and regards
vijay
just use javascript regular expressions to lessen the overhead of posting back to the server.... :)
May 23 '07 #10

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

Similar topics

0
by: Michelle Keys | last post by:
I am trying to call a print function to print a string from a database using javascript. Which is RC_DATA of Varchar2(2500). This is a javascript is not being used. I have a thing that needs to...
1
by: Jorge Ponte | last post by:
hi I have a Web User Control (ascx) - lets call it "My_WUC" - in a Web form. In that WUC I want have a textbox and a button. I want to click on the button and open a popup (I use javascript for...
8
by: rn5a | last post by:
I have gone through a no. of posts in this NewsGroup regarding my problem but alas, couldn't come across one which would have helped me in resolving the issue. My problem is this: An ASPX Form...
2
by: Phil | last post by:
Hi, There is a label and a textbox. There are two buttons: one HTML (buttonA), the other ASP.NET (ButtonB). Clicking on buttonA starts a javascript function, starting on ButtonB triggers...
1
by: KRISHNA PRAVI | last post by:
the error is "runtime error object expected" here is the code....................................................................................... <script language="javascript"...
6
by: john | last post by:
I have the following textbox setup with Text & ToolTip Bindings as follows; I'm using Visual Studio 2008 VB: <asp:TextBox ID="txtDay1" runat="server" Text='<%# Eval("Day1") %>'...
4
by: Peter | last post by:
ASP.NET I have an application which use ASP.NET Autocomplete extender which works great. But I have a question how to update all the fields on the screen using Ajax. Users starts typing in a...
2
Frinavale
by: Frinavale | last post by:
JavaScript in ASP.NET Using JavaScript in ASP.NET pages can make your application seem to work faster and prevent unnecessary calls to the server. JavaScript can be used to perform client-side...
2
by: pankajsingh5k | last post by:
Dear All, Please help me... I had read an article to lazy load a tab in a tabcontainer using an update panel on http://mattberseth.com/blog/2007/07/how_to_lazyload_tabpanels_with.html ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.