An HTML text input has an attribute called \"maxlength\", implemented by browsers, which if set blocks user input after a certain number of characters.
Use a JavaScript framework (Prototype, jQuery, etc.) so that you have cross-browser event support. Write a one liner on keyup to prevent the user from entering the maxlength.
Note: You'll also have to check that length server side.