# how to make a textbox to allow only one decimal point

Page 1 of 1

## 3 Replies - 17354 Views - Last Post: 12 January 2009 - 03:24 PM

### #1 vickycool

Reputation: 0
• Posts: 1
• Joined: 12-January 09

# how to make a textbox to allow only one decimal point

Posted 12 January 2009 - 07:40 AM

how to make a textbox to allow only one decimal point
Is This A Good Question/Topic? 0

## Replies To: how to make a textbox to allow only one decimal point

### #2 JMRKER

Reputation: 133
• Posts: 863
• Joined: 25-October 08

## 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 teampoop

Reputation: 17
• Posts: 140
• Joined: 19-June 08

## 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 JMRKER

Reputation: 133
• Posts: 863
• Joined: 25-October 08

## 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

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }