473,473 Members | 1,984 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to validate numeric value by using Javascript

88 New Member
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 6562
menocomp
5 New Member
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 Recognized Expert Moderator Expert
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
kang jia
88 New Member
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...
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.