mask out some characters from being typed into input field

by Eugene Manager

HTML

<input>

JavaScript

$.fn.noMask = function(regex) { 
      this.on("keypress", function(e) {
        if (regex.test(String.fromCharCode(e.which))) {
            return false;
        }
      });
    }

    $("input").noMask ( /[a-zA-Z]/ );