how to make a textbox to allow only one decimal point
3 Replies - 11427 Views - Last Post: 12 January 2009 - 03:24 PM
#1
how to make a textbox to allow only one decimal point
Posted 12 January 2009 - 07:40 AM
Replies To: how to make a textbox to allow only one decimal point
#2
Re: how to make a textbox to allow only one decimal point
Posted 12 January 2009 - 07:47 AM
Use .toFixed(1) when you set the value of the textbox.
#3
Re: how to make a textbox to allow only one decimal point
Posted 12 January 2009 - 01:44 PM
Another approach could be to split on the decimal points, and if the returned array length is more than 2, you have a fail.
s = "123.1123";
s2 = "123.123.13";
function howManyDecimals(i) {
y = i.split(/\./);
if(y.length>2) return "fail";
return "happy";
}
document.write(howManyDecmials(s)); // happy
document.write(howManyDecimals(s2)); // fail
#4
Re: how to make a textbox to allow only one decimal point
Posted 12 January 2009 - 03:24 PM
Quote
Another approach could be to split on the decimal points, and if the returned array length is more than 2, you have a fail.
Ahh... I thought OP was asking to limit output diplay, not limit input typed.
I guess you could say my thinking was limited!
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|