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

#1 vickycool  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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  Icon User is offline

  • D.I.C Addict

Reputation: 125
  • View blog
  • Posts: 818
  • 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.
:)
Was This Post Helpful? 0
  • +
  • -

#3 teampoop  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 17
  • View blog
  • 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


Was This Post Helpful? 0
  • +
  • -

#4 JMRKER  Icon User is offline

  • D.I.C Addict

Reputation: 125
  • View blog
  • Posts: 818
  • 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! :blink: ;)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1