4 months ago

Regex: check a string

Posted 4 months ago by Romentigo

I have the next method:

isLetter(e) {
                let char = String.fromCharCode(e.keyCode);
                if(/^[А-я\' ІіЇїЄєҐґ]+$/.test(char)){
                    return true;
                else e.preventDefault();

This method doesn't allow to type any characters, except given above. It works on event @keypress. But I've noticed one problem – a user can just paste anything he wants in an input field. How can I validate the whole input field, for example, on @blur event?

Please sign in or create an account to participate in this conversation.