Skip to content

Commit 9328e44

Browse files

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/Faker/Provider/en_US/PhoneNumber.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@
44

55
class PhoneNumber extends \Faker\Provider\PhoneNumber
66
{
7+
/**
8+
* @var array<int, string>
9+
*/
10+
protected static $areaCodeRegexes = [
11+
2 => '(0[1-35-9]|1[02-9]|2[03-589]|3[149]|4[08]|5[1-46]|6[0279]|7[0269]|8[13])',
12+
3 => '(0[1-57-9]|1[02-9]|2[0135]|3[0-24679]|4[167]|5[12]|6[014]|8[056])',
13+
4 => '(0[124-9]|1[02-579]|2[3-5]|3[0245]|4[0235]|58|6[39]|7[0589]|8[04])',
14+
5 => '(0[1-57-9]|1[0235-8]|20|3[0149]|4[01]|5[19]|6[1-47]|7[013-5]|8[056])',
15+
6 => '(0[1-35-9]|1[024-9]|2[03689]|[34][016]|5[017]|6[0-279]|78|8[0-29])',
16+
7 => '(0[1-46-8]|1[2-9]|2[04-7]|3[1247]|4[037]|5[47]|6[02359]|7[02-59]|8[156])',
17+
8 => '(0[1-68]|1[02-8]|2[08]|3[0-28]|4[3578]|5[046-9]|6[02-5]|7[028])',
18+
9 => '(0[1346-9]|1[02-9]|2[0589]|3[0146-8]|4[0179]|5[12469]|7[0-389]|8[04-69])',
19+
];
20+
721
/**
822
* @see https://en.wikipedia.org/wiki/National_conventions_for_writing_telephone_numbers#United_States.2C_Canada.2C_and_other_NANP_countries
923
*/
@@ -89,11 +103,9 @@ public function phoneNumberWithExtension()
89103
*/
90104
public static function areaCode()
91105
{
92-
$digits[] = self::numberBetween(2, 9);
93-
$digits[] = self::randomDigit();
94-
$digits[] = self::randomDigitNot($digits[1]);
106+
$firstDigit = self::numberBetween(2, 9);
95107

96-
return implode('', $digits);
108+
return $firstDigit . self::regexify(self::$areaCodeRegexes[$firstDigit]);
97109
}
98110

99111
/**

0 commit comments

Comments
 (0)