Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > how let insert real number

Reply
Thread Tools

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


 
Reply With Quote
 
 
 
 
George Hester
Guest
Posts: n/a
 
      10-09-2004

"SAN CAZIANO" <> wrote in message news:NlU9d.100248$...
> 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.
 
Reply With Quote
 
 
 
 
Michael Winter
Guest
Posts: n/a
 
      10-09-2004
On Sat, 09 Oct 2004 16:29:33 GMT, SAN CAZIANO <> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
OT: Let me in! Let me in! quasi/various/bob [7.13.86.42] MCSE 7 05-30-2006 10:00 PM
Have a nice day! ...//more of your parables. Pray let us know whoyou are, let us Ravens U. Locksmith Python 1 05-26-2004 11:00 AM
winxp IE will not let you exit, and my comptuer / other folders will not let you open them. Daniel NZ Computing 2 05-11-2004 02:02 AM
Let or not let the text float Luigi Donatello Asero HTML 6 01-15-2004 04:08 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57