aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes only allow user to enter two digits after decimal Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "only allow user to enter two digits after decimal" Watch "only allow user to enter two digits after decimal" New topic
Author

only allow user to enter two digits after decimal

Tariq Ahsan
Ranch Hand

Joined: Nov 03, 2003
Posts: 116
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Nov 03, 2003
Posts: 116
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
why read the keystrokes? You can read the textbox value and determine what is happening.

Eric
Tariq Ahsan
Ranch Hand

Joined: Nov 03, 2003
Posts: 116
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
 
subject: only allow user to enter two digits after decimal