how let insert real number

Discussion in 'Javascript' started by SAN CAZIANO, Oct 9, 2004.

  1. SAN CAZIANO

    SAN CAZIANO Guest

    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
    SAN CAZIANO, Oct 9, 2004
    #1
    1. Advertising

  2. "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.
    George Hester, Oct 9, 2004
    #2
    1. Advertising

  3. 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.
    Michael Winter, Oct 9, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. senthil
    Replies:
    5
    Views:
    1,376
    senthil
    Jan 24, 2004
  2. hari
    Replies:
    6
    Views:
    6,932
    hamilton
    May 2, 2004
  3. Luigi Donatello Asero

    Let or not let the text float

    Luigi Donatello Asero, Jan 15, 2004, in forum: HTML
    Replies:
    6
    Views:
    464
    Steve R.
    Jan 15, 2004
  4. davidj411
    Replies:
    11
    Views:
    1,292
    Kam-Hung Soh
    May 29, 2008
  5. Krishnakant
    Replies:
    0
    Views:
    219
    Krishnakant
    Dec 15, 2008
Loading...

Share This Page