Answers for "onkeypress avoid to type special characters"

0

onkeypress avoid to type special characters

$('input').on('keypress', function (event) {
    var regex = new RegExp("^[a-zA-Z0-9]+$");
    var key = String.fromCharCode(!event.charCode ? event.which : event.charCode);
    if (!regex.test(key)) {
       event.preventDefault();
       return false;
    }
});
Posted by: Guest on September-21-2020

Code answers related to "onkeypress avoid to type special characters"

Browse Popular Code Answers by Language