paste only float number

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • SAN CAZIANO

    paste only float number

    how can i test if I paste in an edit if the new value contains only numbers
    and one ',' to test if I paste only a float ???


  • RobG

    #2
    Re: paste only float number

    SAN CAZIANO wrote:[color=blue]
    > how can i test if I paste in an edit if the new value contains only numbers
    > and one ',' to test if I paste only a float ???
    >[/color]

    If that is /exactly/ what you want:

    Enter a value (<i>x,x</i>)
    <input type="text" id="xx" size="10" onblur="
    checkVal(this.v alue);">

    <script type="text/javascript">
    function checkVal(x){
    alert((/^\d+,\d+$/.test(x))? 'OK' : 'ughh');
    }
    </script>

    The above will fail on any value that is not one or more digits, then
    a comma, then one or more digits. It will not tolerate any spaces
    before or after the expression, or any other character.

    Beware: using a comma ',' for a decimal point '.' may be confusing to
    many visitors not familiar with that notation and who expect it to be
    used for a thousands separator.




    --
    Rob

    Comment

    Working...