469,323 Members | 1,444 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,323 developers. It's quick & easy.

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 6353
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

Post your reply

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

Similar topics

5 posts views Thread by Rob Wahmann | last post: by
7 posts views Thread by juicy | last post: by
3 posts views Thread by samuelberthelot | last post: by
nathj
4 posts views Thread by nathj | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.