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

how to validate numeric value by using Javascript

hi, now i want to validate numeric value which user filled in in text box, it can have 2 decimal places. what is the regular expression i can use to achieve this? anyone can help?

can reply me ASAP, it is urgent. thanks in advance
Jul 25 '07 #1
3 6553
Expand|Select|Wrap|Line Numbers
  1. function CheckIntegers(e)
  2.     {
  3.         var keynum
  4.         var keychar
  5.         var numcheck
  6.         if(window.event) // IE
  7.         {
  8.             keynum = e.keyCode
  9.         }
  10.         else if(e.which) // Netscape/Firefox/Opera
  11.         {
  12.             keynum = e.which
  13.         }
  14.         keychar = String.fromCharCode(keynum)
  15.         numcheck = /\d/
  16.         return numcheck.test(keychar)
  17.     }
Jul 25 '07 #2
gits
5,390 Expert Mod 4TB
hi ...

you may use a regEx but a simple way is to check the value you want with:

Expand|Select|Wrap|Line Numbers
  1. isNaN(value)
that returns true in case value isN(ot)aN(umber) ... otherwise it returns false ;)

kind regards
Jul 25 '07 #3
Expand|Select|Wrap|Line Numbers
  1. function CheckIntegers(e)
  2.     {
  3.         var keynum
  4.         var keychar
  5.         var numcheck
  6.         if(window.event) // IE
  7.         {
  8.             keynum = e.keyCode
  9.         }
  10.         else if(e.which) // Netscape/Firefox/Opera
  11.         {
  12.             keynum = e.which
  13.         }
  14.         keychar = String.fromCharCode(keynum)
  15.         numcheck = /\d/
  16.         return numcheck.test(keychar)
  17.     }
besides this long method, do you know any regular expression which can help to check number value and its decimal places( i only need 2 decimal places). thanks for it.
Jul 26 '07 #4

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

Similar topics

10
by: KathyB | last post by:
Hi, I just can't get this quite right. I use the following function to validate a user entry. I need to allow negative numbers including those with decimals (e.g., -.5). The following allows the...
5
by: Rob Wahmann | last post by:
Not sure if my first message went through because of the attachment... I'm currently using formchek.js to validate various form fields, however, I cannot figure out how to validate a field with a...
6
by: Abby Lee | last post by:
I must confirm the user enters a value for each fund they need. I do not know how many fund entries there will be...it's expandable to handle each users needs. I must varify each fund they enter is...
7
by: juicy | last post by:
I done a numeric field checking as below, but I found that if I insert float number (10.01), it validate it as non numeric and return false.. What is going wrong? if...
3
by: samuelberthelot | last post by:
Hello, I would like to validate a date in a textbox on the onChange event. The date must be in the format 01/01/2007 I would like to use a regular expression to validate it but I'm not very...
5
nathj
by: nathj | last post by:
Hi, I have been looking around the forum and the web for a way to achieve this and so far I have drawn a blank. So I head to the forum as I'm sure someone knows how to do this. I have a form...
4
nathj
by: nathj | last post by:
Hi, I'm working on a registration form and one of the checks I need to perform as the form is used is on the username. I need to ensure that it is not already in use. I am getting a little...
1
by: SkipNRun | last post by:
I am a novice when comes to JavaScript, AJAX. I am working on a form, which will allow users to update their contact information. In order to make the form flexible, I need to use pull down list. ...
1
by: mbarnhizer | last post by:
Hello All, Trying to figure out how to validate a series of questions on an online test. I am thinking that VB or Javascript is the best route, but your input may make a difference. The site i...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.