Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

only allow user to enter two digits after decimal

 
Tariq Ahsan
Ranch Hand
Posts: 116
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am new to JavaScript. Wondering if there is a way an user can be prevented to enter more than two digits after the decimal point on a field? User would be able enter a whole number or a decimal value which would eventually get mapped to a database table column of NUMBER(9,2) datatype?

Any idea this can be best done?

Thanks

Tariq
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no way to do it with html to do it. You can write JavaScript to remove the numbers after the decimal, you still would need to do it on the server too.

Eric
 
Tariq Ahsan
Ranch Hand
Posts: 116
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for response. I know I have to do it using a JavaScript. I am toying around using event.keyCode. For decimal value it is coming out to be the values - 190 and 110. I am trying out something like the follow to see if the entered key value is a decimal -



just to test if a decimal key has been entered. I guess now I have to find a way to count the number of keys pressed. Once it hits the count to 2 I have to find way to disallow the user to enter any more digits.

Would you know that can be done? Or there are much simpler way to achieve this?

Thanks once again.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why read the keystrokes? You can read the textbox value and determine what is happening.

Eric
 
Tariq Ahsan
Ranch Hand
Posts: 116
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Found this url which had I pretty much needed -

http://www.codingforums.com/archive/index.php/t-13452.html
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic