PDA

View Full Version : allow only numeric data including decimal



abs0lut
01-10-2009, 12:38 AM
the user cannot type letters or special characters into the input field.
could you please help me?

Snookerman
01-10-2009, 09:43 AM
These threads should be helpful:
http://www.cambiaresearch.com/c4/029c978b-aac5-472e-97a8-95b256f5febd/How-Can-I-Use-Javascript-to-Allow-Only-Numbers-to-Be-Entered-in-a-TextBox.aspx (http://www.cambiaresearch.com/c4/029c978b-aac5-472e-97a8-95b256f5febd/How-Can-I-Use-Javascript-to-Allow-Only-Numbers-to-Be-Entered-in-a-TextBox.aspx)
http://www.go4expert.com/forums/showthread.php?t=2359 (http://www.go4expert.com/forums/showthread.php?t=2359)

Good luck!

rangana
01-10-2009, 10:11 AM
<input type="text" onkeyup="this.value=!this.value.match(/[\d.]$/)?this.value.substring(0,this.value.length-1):this.value;">

vwphillips
01-10-2009, 11:23 AM
for +ve and -ve floating point


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
</head>
<script language="JavaScript" type="text/javascript">
/*<![CDATA[*/

function zxcFloat(obj){
obj.value=obj.value.replace(/[^-?\d\.]/g,'');
obj.value=parseFloat(obj.value);
}
/*]]>*/
</script>
<body>
<input name="" onblur="zxcFloat(this)"/>
</body>

</html>

abs0lut
01-10-2009, 11:57 PM
if the user press any letter/special characters, it will not appear in the textbox.
thanks