You would be better off by using a library like maskedinput.js. You can then setup your text input like follows:
jQuery(function($){ $("#your_input").mask("999"); }); UPDATE
you can use a validator for forms and preset specific types of fields to validate