Tool for filtering input chars defined by regexp pattern.
npm install input-char-filter
<input type="text" data-input-type="number">
<input type="text" data-input-type="letters">
var patterns = {
numbers: /[0-9]/,
letters: /[a-zA-Z]/
};
$('[data-input-type="number"]').on('keypress', inputCharFilter(patterns.numbers));
$('[data-input-type="letters"]').on('keypress', inputCharFilter(patterns.letters));
You can pass callback function that provided by character value at the first argument.
var inputLogger = inputCharFilter(patterns.numbers, function(chr) {
console.log(chr);
});
MIT