Take the 2-minute tour ×

I have a textbox on my page. I have a javascript that the user just write numbers and dots in the textbox. But unfortunately that's not enough. The user must be limited if it puts a dot then it just can write digits after. Are not there validation controls or ajax tool kit, or i have to do it on onkeypress event?

share|improve this question
What would ajax have to do with it? –  T.J. Crowder Mar 19 '12 at 12:14
You should validate when the data is sent, not on input. Text can be entered without dispatching a keypress event, e.g. pasted or dropped. –  RobG Mar 19 '12 at 12:24
add comment

3 Answers

at onblur/onkeyup event of that input:text just check if the entered value match against /\.\d{2}$/ regular expression

share|improve this answer
add comment

you can try this regexp;

function dotdot(val){
    var rx = /\.\./;
    return rx.test(val);

This way you can ensure the user doesn't type a dot after another dot.

share|improve this answer
add comment
var textbox = document.getElementById("ele_id");
}, false);

just tested it in firefox/firebug, you could use "onkeyup" in html or jquery's bind() to make event handler work in IE

share|improve this answer
add comment

Your Answer


