I have a text input, which could be any combination of alphanumeric characters.

<input type="text" name="example">

Here's my problem.

If the user is entering letters only, or a combination of letters and numbers, then no problem, let them submit it.

However, if the user is entering an integer, any value above 99 will always be an invalid entry (as far as the backend is concerned). So on the front end, I would like to prevent them from entering any integer three or more digits long.

So if I try to type the number 100, for example, I want to create a javascript that prevents the second "0" from being typed. If I were typing 10wQwerty, no intervention is needed, since alphanumeric is okay.

How can I accomplish this in Javascript? Google has not turned up much of anything. Are there any libraries or anything that I am unaware of?

Thank you!

1 Answers 11

JavaScript's onkeyup event and Regular Expressions should do the trick.

Put in the effort.

Not the answer you're looking for? Browse other questions tagged or ask your own question.