Posted By

blackf0rk on 03/12/09


decimal validation validate decimals

Versions (?)

Validate Decimals with Javascript

 / Published in: JavaScript

Validating a decimal such as a measurement of time or currency (10.5 or 0.4). This function will return the correct number. If you feed in "10.5foo" the function will spit back 10.5. If you feed in "bar" the function will return nothing.

  1. function valNum(inNum {
  2. var RegEx = /[0-9]{1,8}\.?[0-9]{0,2}/;
  3. var ValidNumber = inNum.match(RegEx);
  4. return ValidNumber;
  5. }

Report this snippet  

You need to login to post a comment.