input-char-filter
v1.0.1
Published
Tool for filtering input chars defined by regexp pattern
Downloads
7
Maintainers
Readme
Input Char Filter
Tool for filtering input chars defined by regexp pattern.
Install
npm install input-char-filter
Usage
HTML
<input type="text" data-input-type="number">
<input type="text" data-input-type="letters">
Javascript
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));
Callback
You can pass callback function that provided by character value at the first argument.
var inputLogger = inputCharFilter(patterns.numbers, function(chr) {
console.log(chr);
});
License
MIT