Here's an example that limits a form field to contain only numeric input (on the fly, of course! Try typing in stuff other than numbers into the above box- you can't. By checking to see whether the keycode of the key pressed as the user types falls within the range of the number keys (48~57), and if not, returns false, which disables the keypress action.
How did I know 48 to 57 represents the keycode of the numeric keys?
Now you can ask questions directly to me on my new site ASPForums.
This site and all of its contents are referring to Angular JS (version 1.x), if you are looking for the latest Angular, please visit
If you want to limit the characters your user/visitor can type in an input field, you CAN, using the maxlength attribute.
Both approaches give us a reference to the desired form element.
In order to set the value of a textarea field element in a form, we can use the following code: See the demo When the page loads, the textarea field “service_complaint” has a note written for the user: “Please enter your complaint briefly”, but when focus is set to that field, this message disappears, as it should.
will not handle the paste if it is done through a context menu or a browser menu.
It would really annoy me as a user if I had pasted a whole piece of something in a textarea, clicked submit, and only saw a small portion of it go through without any response.
I know you want to avoid j Query, but as the solution requires Java Script, this solution (using j Query 1.4) is the most consise and robust.
This approach works if you do not need to screen for paste.
See this answer for a timer based approach stackoverflow.com/a/10390626/[email protected] Stodola - Indeed you cannot.