javascript input box filter sample

<input type="text" v-on:keypress="
        let letterNumber = /^[0-9a-z_]+$/;
        let keyCode = ($event.keyCode ? $event.keyCode : $event.which);
        let text = String.fromCharCode(keyCode);
        if (! text.match(letterNumber)) {
            $event.preventDefault();
        }
">