Velocity Reviews > how let insert real number

how let insert real number

SAN CAZIANO
Guest
Posts: n/a

 10-09-2004
how can i insert only a real number (an integer with only one decimal
separator) in a edit field

perhaps in onchange event I have to test if the decimal separator in the
text is >0 I simply have to put it as a null key

George Hester
Guest
Posts: n/a

 10-09-2004

"SAN CAZIANO" <(E-Mail Removed)> wrote in message news:NlU9d.100248\$(E-Mail Removed)...
> how can i insert only a real number (an integer with only one decimal
> separator) in a edit field
>
>
> perhaps in onchange event I have to test if the decimal separator in the
> text is >0 I simply have to put it as a null key
>
>

Hi SAN.

I'm not sure if I understand the beginning of your post. An Iinteger NEVER has a decimal in it. In other words
6.0 is NOT an Integer. It is Real yes but not an Integer. Seperators are usually used in how an array is contructed For example var arr = 3,5,7,8 are comma seperated Integers; the array is arr. If you want to use . as a seperator then 3.5.7.8 are decimal seperated Integers. I don't think you can have decimal seperated Real numbers.

As for your javascript ? the experts can probably give you what you want. But this amatuer doesn't understand your intro.

Michael Winter
Guest
Posts: n/a

 10-09-2004
On Sat, 09 Oct 2004 16:29:33 GMT, SAN CAZIANO <(E-Mail Removed)> wrote:

> how can i insert only a real number (an integer with only one decimal
> separator) in a edit field
>
> perhaps in onchange event I have to test if the decimal separator in the
> text is >0 I simply have to put it as a null key

The best way to check an input format is using a regular expression. Real
numbers can use this basic check:

if(/^(0|[1-9]\d*)\.\d\d\$/.test( string )) {
// test succeeded

That expression ensures that a number cannot include leading zeros, and
must have a decimal portion containing two numbers.

0.14 and 12.00

are valid numbers, but

02.50 and 1.0 and .25

are not. If you have specific requirements, such as the inclusion of
integer values, or a range of allowable decimal digits (rather than the
current two), they should be easy to accomodate. Just ask.

Hope that helps,
Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.