U
U
ultrabi42021-08-11 11:58:44
Regular Expressions
ultrabi4, 2021-08-11 11:58:44

Correct regexp for the "phone" field. How to consider 8 and 7 when dialing a number?

Hello,

I'm using the example from this solution:

https://codesandbox.io/s/248vzprz2p?file=/index.js

To implement the phone mask.

const phoneNumberMask = [
  "8",
  "(",
  /[1-9]/,
  /\d/,
  /\d/,
  ")",
  " ",
  /\d/,
  /\d/,
  /\d/,
  "-",
  /\d/,
  /\d/,
  /\d/,
  /\d/
];


In this case, when you enter 8, it is not taken into account and the further set begins already in brackets, which is what you need.
But people start dialing from 7, and in this case the phone is indicated incorrectly, i.e. 8(7....
How can I change the regular expression so that when typing 8 and 7 they count as 8 and the input starts with an open bracket?

Thanks

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