K
K
kimqarkimqarkimqar2021-07-30 15:36:59
JavaScript
kimqarkimqarkimqar, 2021-07-30 15:36:59

Phone mask regular?

There is a mask for phone input:

'formData.phoneNumber': function (value) {
                            return Validator.value(value).required().regex(/\+\d{6,20}/);
                        }

This regular expression makes the minimum number of characters in the form for the phone 6.
Everything works, except for spaces in the form. If you enter, for example, a space in the number (7906 4703333), then this regular expression will return an error in the form, but if you remove the space and leave just 79064703333, then the validation will work correctly.
How to make a regular expression that will skip spaces in the form?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Volodymyr Palamar, 2021-07-30
@GORNOSTAY25

Try it differently

function (value) {
value = value.replace(/\s/g,"") ///<== Удаляет все пробелы переносы и тд
return Validator.value(value).required().regex(/\+\d{6,20}/);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question