JavaScript codes to only accept alphabet letters and numbers from your users



Sometimes we ask our users to type in something and we only accept alphabet numbers and/or letters, so they should not type something like #$%!@$&%(…

So, first we need a variable that holds user’s text. For example, “userText” with value of an input box containing user’s text. Then, we examine that variable, does it contain anything but letters and numbers or not.

Here is the codes:

Also watch this demonstration video to see how it works:



Published by

Habibie

Habibie is an Indonesian freelance frontend-backend web developer and cross platform mobile app programmer. He's also good at graphics design, video editing, visual effects and animation.

Leave a Reply

Your email address will not be published. Required fields are marked *