Allow only specific characters

I would like to block the input of all characters except 0-9, az, AZ, only alphanumeric characters. Therefore, when someone dials! for example, nothing is written to the input. How can i do this?

+3
source share
2 answers

You need to write a function that listens onkeypressfor the event for the form field, then check to see if the form contains any unwanted characters, and if that happens, you will update the field to remove those characters.

+2
source

Or maybe you can use the Alphanumeric plugin for jQuery :

$('#yourInput').alphanum();
0
source

Source: https://habr.com/ru/post/1744536/


All Articles