Connecting Tech Pros Worldwide Forums | Help | Site Map

paste only float number

SAN CAZIANO
Guest
 
Posts: n/a
#1: Jul 23 '05
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
Guest
 
Posts: n/a
#2: Jul 23 '05

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.value);">

<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
Closed Thread