[Javascript] Number validation with digit grouping

Dan Costea costea.dan at ssi-schaefer.ro
Mon Oct 21 06:48:12 CDT 2002


I wrote a function for you:

   function floatTest (sNr)
   {
    var reFloatF1 = /^((\d+(\.\d*)?)|((\d*\.)?\d+))$/; // format 1
    var reFloatF2 = /^((\d+(\,\d*)?)|((\d*\,)?\d+))$/; // format 2

    return (reFloatF1.test (sNr) || reFloatF2.test (sNr));
   }

This should solve your problem.

Dan.

----- Original Message ----- 
From: "Tobias Barlind" <tobias.barlind at infostruct.se>
To: <javascript at LaTech.edu>
Sent: Monday, October 21, 2002 12:26 PM
Subject: [Javascript] Number validation with digit grouping


> Does anyone have a good snippet that validates a string of numbers that
> has digit grouping?
> 
> I.e "12,200.50"
> 
> isNaN returns true on this.
> 
> And I can't just simply remove all "," because I have to deal with
> different languages having different decimal signs like "," instead of
> "." :)
> 
> //B
> 
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript




More information about the Javascript mailing list