Home > Blockchain >  How to make a phone mask with Regexp
How to make a phone mask with Regexp

Time:12-09

how to make a phone number mask name regexp pattern

/(^8|7|\ 7)((\d{10})|(\s\(\d{3}\)\s\d{3}\s\d{2}\s\d{2}))/

UPD

This code works for me, but I do not know how to do how to make 7 automatically become at the beginning

var x = value.replace(/\D/g, '').match(/(\d{0,3})(\d{0,3})(\d{0,4})/);

var result = !x[2] ? x[1] : '('   x[1]   ') '   x[2]   (x[3] ? '-'   x[3] : '');

setPhone(result)

CodePudding user response:

Try this:

^\ 7\s?\(?\d{3}\)?\s?\d{3}-?\d{2}-?\d{2}$

Demo

CodePudding user response:

^(\ \d{1,2}\s)?\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4}$

This works for me but needs to define what kind of regex you want like what country and states phone number

  • Related