How do I get an input field (text) to accept only numbers and to automatically format it to two decimal places, as the user is typing in each digit?
For example, the default value of the field is 0.00
User wants to enter 23.50
Step 1: user types 2 - field shows 0.02
Step 2: user types 3 - field shows 0.23
Step 3: user types 5 - field shows 2.35
Step 4: user types 0 - field shows 23.50
Thanks in advance!
the following regex expression matches 99.99, 99999.99, etc.
use jQuery’s
.live()function to wire the keyup event to your text box.when keyup happens, check the value of the text box against that regex expression and do what you wish with your answer.
to make it work from right to left you could reformat the string…
stuff that logic inside your live hook.