Please see my comment to the question. Is looks like validation of some floating-point input. Who cares how many digits are there. You only need to take care of valid format, and, on top of it, probably a valid range. But how?
Failure will be indicated by null value returned. If parsing is successful, you get floating-point numeric object which you can additionally check for the expect range of values. That's all.
Alternatively or additionally, you can use masked text box
for input. Please see, for example: http://jsfiddle.net/SO_AMK/SEXAj