Re: FN-FORUM: js form validation functions
date posted 1st September 2006 12:50
On Friday 01 September 2006 12:47, Rob Garbutt wrote:
> Hi all,
>
> Does anyone have or know where to find form validation functions for all
> the different data types? e.g. int, short, float, long, double etc etc?
>
JavaScript represents /all/ numbers as 64-bit floating point values - it makes
no distinction between integer types and floating point types.
You can obtain a number from a string with the global parseFloat(s) and
parseInt(s, [radix]) functions. Or with the Number constructor. Using new
Number(s) returns a NUmber object, while using Number(s) returns a numerical
value.
To validate numerical input into specific ranges, you'll have to write
functions which check the range of numerical values.
e.g.
function isInt(s)
{
var v = parseInt(s);
return ((!isNaN(v)) && (v >= -32767) && (v