/input-char-filter

🔤 Tool for filtering input chars defined by regexp pattern

Primary LanguageJavaScriptMIT LicenseMIT

Input Char Filter

npm

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