Forum Moderators: open

Message Too Old, No Replies

Decimal and numeric validation of text field

Limit number of digit before and after decimal

         

jbhavin

6:04 am on Jul 14, 2004 (gmt 0)

10+ Year Member



Guys,

I have to limit number of digits before decimal to 6 and after decimal to 2 digits..

How do go about? its shloud happen onBlur even of a text box...

so if i enter 1000.10 it should accept and 999999.99 max it shloud accept

Please Help

Bernard Marx

7:24 am on Jul 14, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<head>
<script>
function check(box)
{
var val = box.value/1
// limit to 2 dec places (rounding up, if needed)
box.value = Math.round(val*100)/100
// check <7 after dec point
if(!(val<1000000))
alert("More than 6 figures after decimal point")

}
</script>
</head>
<body>
<form>
<input type="text" onblur="check(this)" />
</form>
</body>