473,395 Members | 2,798 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.

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 6560
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...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.