input-pattern-restrictor

1.0.0 • Public • Published

input-pattern-restrictor

Restrict event propagation into input-like elements by validating the inputted value via regex.

Usage

var inputPatternRestrictor = require('input-pattern-restrictor');

window.onload = function() {

    function restrictInput(event){
        inputPatternRestrictor(event, /^\d{0,2}\s?\d{0,3}\s?\d{0,3}\s?\d{0,3}$/);
    }

    element.addEventListener('keypress', restrictInput);
    element.addEventListener('paste', restrictInput);
};

Example

npm run example

/input-pattern-restrictor/

    Package Sidebar

    Install

    npm i input-pattern-restrictor

    Weekly Downloads

    1

    Version

    1.0.0

    License

    ISC

    Unpacked Size

    77.1 kB

    Total Files

    7

    Last publish

    Collaborators

    • korynunn