it is fairly simple. just use maxlength="##", replace ## with the required number. or if you want it to appear more attractive, i suggest you to do THIS or THIS to get this thing done! hope it helps.
Thanks but after seeing that i figured out that there wasn't actually any need for javascript. Just the tag maxlength="10" helped. Javascript makes it look not good. If u type fast, u see that all u type can be there but as soon as u stop then it disappears but by using the simple maxlength even typing fast wont make any extra text appear.
If it is for something important then you will need to use a server side language to cut the string to 10 characters. The HTML can be changed by the end user, no good for "sensitive" info.
I would still suggest adding a server side check of the length to make sure nobody tries to game the system.