Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mobile phone number pattern for France #859

Open
wants to merge 1 commit into
base: 1.23
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 35 additions & 15 deletions src/Faker/Provider/fr_FR/PhoneNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class PhoneNumber extends \Faker\Provider\PhoneNumber
'+33 (0)3 ## ## ## ##',
'+33 (0)4 ## ## ## ##',
'+33 (0)5 ## ## ## ##',
'+33 (0)6 ## ## ## ##',
'+33 (0)6 {{phoneNumber06WithSeparator}}',
'+33 (0)7 {{phoneNumber07WithSeparator}}',
'+33 (0)8 {{phoneNumber08WithSeparator}}',
'+33 (0)9 ## ## ## ##',
Expand All @@ -23,7 +23,7 @@ class PhoneNumber extends \Faker\Provider\PhoneNumber
'+33 3 ## ## ## ##',
'+33 4 ## ## ## ##',
'+33 5 ## ## ## ##',
'+33 6 ## ## ## ##',
'+33 6 {{phoneNumber06WithSeparator}}',
'+33 7 {{phoneNumber07WithSeparator}}',
'+33 8 {{phoneNumber08WithSeparator}}',
'+33 9 ## ## ## ##',
Expand All @@ -33,7 +33,7 @@ class PhoneNumber extends \Faker\Provider\PhoneNumber
'03########',
'04########',
'05########',
'06########',
'06{{phoneNumber06}}',
'07{{phoneNumber07}}',
'08{{phoneNumber08}}',
'09########',
Expand All @@ -43,7 +43,7 @@ class PhoneNumber extends \Faker\Provider\PhoneNumber
'03 ## ## ## ##',
'04 ## ## ## ##',
'05 ## ## ## ##',
'06 ## ## ## ##',
'06 {{phoneNumber06WithSeparator}}',
'07 {{phoneNumber07WithSeparator}}',
'08 {{phoneNumber08WithSeparator}}',
'09 ## ## ## ##',
Expand All @@ -52,13 +52,13 @@ class PhoneNumber extends \Faker\Provider\PhoneNumber
// Mobile phone numbers start by 06 and 07
// 06 is the most common prefix
protected static $mobileFormats = [
'+33 (0)6 ## ## ## ##',
'+33 6 ## ## ## ##',
'+33 (0)6 {{phoneNumber06WithSeparator}}',
'+33 6 {{phoneNumber06WithSeparator}}',
'+33 (0)7 {{phoneNumber07WithSeparator}}',
'+33 7 {{phoneNumber07WithSeparator}}',
'06########',
'06{{phoneNumber06}}',
'07{{phoneNumber07}}',
'06 ## ## ## ##',
'06 {{phoneNumber06WithSeparator}}',
'07 {{phoneNumber07WithSeparator}}',
];

Expand All @@ -73,6 +73,26 @@ class PhoneNumber extends \Faker\Provider\PhoneNumber
'+33#########',
];

public function phoneNumber06()
{
$phoneNumber = $this->phoneNumber06WithSeparator();

return str_replace(' ', '', $phoneNumber);
}

/**
* Only 0601 to 0638, 0640 to 0689, 0695 and 0698 to 0699 are acceptable prefixes with 06
*
* @see https://www.arcep.fr/la-regulation/grands-dossiers-thematiques-transverses/la-numerotation.html#c8961
* @see https://www.itu.int/itu-t/nnp/#/numbering-plans?country=France%C2%A0&code=33
*/
public function phoneNumber06WithSeparator()
{
$regex = '([0-24-8]\d|3[0-8]|9[589])( \d{2}){3}';

return static::regexify($regex);
}

public function phoneNumber07()
{
$phoneNumber = $this->phoneNumber07WithSeparator();
Expand All @@ -81,16 +101,16 @@ public function phoneNumber07()
}

/**
* Only 073 to 079 are acceptable prefixes with 07
* Only 0730 to 0789 are acceptable prefixes with 07
*
* @see http://www.arcep.fr/index.php?id=8146
* @see https://www.arcep.fr/la-regulation/grands-dossiers-thematiques-transverses/la-numerotation.html#c8961
* @see https://www.itu.int/itu-t/nnp/#/numbering-plans?country=France%C2%A0&code=33
*/
public function phoneNumber07WithSeparator()
{
$phoneNumber = $this->generator->numberBetween(3, 9);
$phoneNumber .= $this->numerify('# ## ## ##');
$regex = '([3-8]\d)( \d{2}){3}';

return $phoneNumber;
return static::regexify($regex);
}

public function phoneNumber08()
Expand Down Expand Up @@ -121,9 +141,9 @@ public function phoneNumber08()
*/
public function phoneNumber08WithSeparator()
{
$regex = '([012]{1}\d{1}|(9[1-357-9])( \d{2}){3}';
$regex = '([012]\d|(9[1-357-9])( \d{2}){3}';

return $this->regexify($regex);
return static::regexify($regex);
}

/**
Expand Down
24 changes: 18 additions & 6 deletions test/Faker/Provider/fr_FR/PhoneNumberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,49 @@ final class PhoneNumberTest extends TestCase
public function testMobileNumber(): void
{
$mobileNumber = $this->faker->mobileNumber();
self::assertMatchesRegularExpression('/^(\+33 |\+33 \(0\)|0)(6|7)(?:(\s{1})?\d{2}){4}$/', $mobileNumber);
self::assertMatchesRegularExpression('/^(\+33 |\+33 \(0\)|0)([67])(?:(\s)?\d{2}){4}$/', $mobileNumber);
}

public function testMobileNumber06Format(): void
{
$mobileNumberFormat = $this->faker->phoneNumber06();
self::assertMatchesRegularExpression('/^([0-24-8]\d|3[0-8]|9[589])(\d{2}){3}$/', $mobileNumberFormat);
}

public function testMobileNumber06WithSeparatorFormat(): void
{
$mobileNumberFormat = $this->faker->phoneNumber06WithSeparator();
self::assertMatchesRegularExpression('/^([0-24-8]\d|3[0-8]|9[589])( \d{2}){3}$/', $mobileNumberFormat);
}

public function testMobileNumber07Format(): void
{
$mobileNumberFormat = $this->faker->phoneNumber07();
self::assertMatchesRegularExpression('/^([3-9]{1})\d(\d{2}){3}$/', $mobileNumberFormat);
self::assertMatchesRegularExpression('/^([3-8]\d)(\d{2}){3}$/', $mobileNumberFormat);
}

public function testMobileNumber07WithSeparatorFormat(): void
{
$mobileNumberFormat = $this->faker->phoneNumber07WithSeparator();
self::assertMatchesRegularExpression('/^([3-9]{1})\d( \d{2}){3}$/', $mobileNumberFormat);
self::assertMatchesRegularExpression('/^([3-8]\d)( \d{2}){3}$/', $mobileNumberFormat);
}

public function testServiceNumber(): void
{
$serviceNumber = $this->faker->serviceNumber();
self::assertMatchesRegularExpression('/^(\+33 |\+33 \(0\)|0)8(?:(\s{1})?\d{2}){4}$/', $serviceNumber);
self::assertMatchesRegularExpression('/^(\+33 |\+33 \(0\)|0)8(?:(\s)?\d{2}){4}$/', $serviceNumber);
}

public function testServiceNumberFormat(): void
{
$serviceNumberFormat = $this->faker->phoneNumber08();
self::assertMatchesRegularExpression('/^((0|1|2)\d{1}|9[^46])\d{6}$/', $serviceNumberFormat);
self::assertMatchesRegularExpression('/^(([012])\d|9[^46])\d{6}$/', $serviceNumberFormat);
}

public function testServiceNumberWithSeparatorFormat(): void
{
$serviceNumberFormat = $this->faker->phoneNumber08WithSeparator();
self::assertMatchesRegularExpression('/^((0|1|2)\d{1}|9[^46])( \d{2}){3}$/', $serviceNumberFormat);
self::assertMatchesRegularExpression('/^(([012])\d|9[^46])( \d{2}){3}$/', $serviceNumberFormat);
}

public function testE164PhoneNumberFormat(): void
Expand Down
Loading