O
O
oskar barin2021-11-22 13:44:48
JavaScript
oskar barin, 2021-11-22 13:44:48

How to make phone validation on form input?

How to make validation on the form when entering or when inserting a record of this type into the form +7 (999) 999-99-99 ?
at the output I want the form to display this type +79999999999 I

wrote such a validation.

validatePhone(event) {
        const { target } = event;
        const validatePhone = target.value.replace(/\D/g, '').match(/(\d{0,1})(\d{0,10})/);
        target.value = '+7'+validatePhone[2];
        this.formPhone.Phone = target.value = '+7'+validatePhone[2];
    }


This code cuts a lot when I insert it into the form +7 (999) 999-99-99, then only +7999999 is displayed in the form

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question