0

I found this javascript regex to validate the different format the US phone numbers can be written. But it has problem: it fails to match the second rule in this group:

The first group of three digits, know as area code start with a number 2–9, followed by 0–8, and then any third digit.

It accepts 9 whereas it should only accept numbers from (0-8). This regex show it all: http://regexr.com/3ackc

/^(1[- .]?)?(\([2-9]\d{2}\)[. -]?|[2-9]\d{2}[. -]?)[2-9]\d{2}[- .]?\d{4}$/gm
georg
  • 211,518
  • 52
  • 313
  • 390
Adorablepolak
  • 157
  • 4
  • 16

1 Answers1

0

I’m not fully aware of the notation and exact restrictions of US phone numbers, so I referred to Wikipedia and came up with this:

/^[2-9][0-8]\d\-?[2-9]([02-9]{2}|[02-9]\d||\d[02-9])\-?\d{4}$/g

Matches in Regexhelper

Tim S.
  • 13,597
  • 7
  • 46
  • 72