[Jquery] Not allow input special characters

$('.inputfilename').keypress(function(e){
    debugger;
    var regex = /[!@#$%\^&*(){}[\]<>?/|\-:;+_=,.~`]/;
    if(!regex.test(String.fromCharCode(e.keyCode))) {
        $(this).val($(this).val() + String.fromCharCode(e.keyCode).replace(regex, ''));
    }
    e.preventDefault();
});


$('.inputfilename').bind ("input propertychange", function (e) {
    debugger;
    var regex = /[!@#$%\^&*(){}[\]<>?/|\-:;+_=,.~`]/g;
    var regex_value = "/[!@#$%\^&*(){}[\]<>?/|\-:;+_=,.~`]/";
    if(!regex.test(String.fromCharCode(e.keyCode))) {
        $(this).val($(this).val().replace(regex, ""));
    }
});

Comments

Popular Posts