1.0.0 • Published 6 years ago

input-pattern-restrictor v1.0.0

Weekly downloads
2
License
ISC
Repository
github
Last release
6 years ago

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