Skip to content

Commit 8d45ca3

Browse files
committed
Fix mobile phone number pattern for France
1 parent 4dae775 commit 8d45ca3

File tree

2 files changed

+53
-21
lines changed

2 files changed

+53
-21
lines changed

src/Faker/Provider/fr_FR/PhoneNumber.php

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class PhoneNumber extends \Faker\Provider\PhoneNumber
1313
'+33 (0)3 ## ## ## ##',
1414
'+33 (0)4 ## ## ## ##',
1515
'+33 (0)5 ## ## ## ##',
16-
'+33 (0)6 ## ## ## ##',
16+
'+33 (0)6 {{phoneNumber06WithSeparator}}',
1717
'+33 (0)7 {{phoneNumber07WithSeparator}}',
1818
'+33 (0)8 {{phoneNumber08WithSeparator}}',
1919
'+33 (0)9 ## ## ## ##',
@@ -23,7 +23,7 @@ class PhoneNumber extends \Faker\Provider\PhoneNumber
2323
'+33 3 ## ## ## ##',
2424
'+33 4 ## ## ## ##',
2525
'+33 5 ## ## ## ##',
26-
'+33 6 ## ## ## ##',
26+
'+33 6 {{phoneNumber06WithSeparator}}',
2727
'+33 7 {{phoneNumber07WithSeparator}}',
2828
'+33 8 {{phoneNumber08WithSeparator}}',
2929
'+33 9 ## ## ## ##',
@@ -33,7 +33,7 @@ class PhoneNumber extends \Faker\Provider\PhoneNumber
3333
'03########',
3434
'04########',
3535
'05########',
36-
'06########',
36+
'06{{phoneNumber06}}',
3737
'07{{phoneNumber07}}',
3838
'08{{phoneNumber08}}',
3939
'09########',
@@ -43,7 +43,7 @@ class PhoneNumber extends \Faker\Provider\PhoneNumber
4343
'03 ## ## ## ##',
4444
'04 ## ## ## ##',
4545
'05 ## ## ## ##',
46-
'06 ## ## ## ##',
46+
'06 {{phoneNumber06WithSeparator}}',
4747
'07 {{phoneNumber07WithSeparator}}',
4848
'08 {{phoneNumber08WithSeparator}}',
4949
'09 ## ## ## ##',
@@ -52,13 +52,13 @@ class PhoneNumber extends \Faker\Provider\PhoneNumber
5252
// Mobile phone numbers start by 06 and 07
5353
// 06 is the most common prefix
5454
protected static $mobileFormats = [
55-
'+33 (0)6 ## ## ## ##',
56-
'+33 6 ## ## ## ##',
55+
'+33 (0)6 {{phoneNumber06WithSeparator}}',
56+
'+33 6 {{phoneNumber06WithSeparator}}',
5757
'+33 (0)7 {{phoneNumber07WithSeparator}}',
5858
'+33 7 {{phoneNumber07WithSeparator}}',
59-
'06########',
59+
'06{{phoneNumber06}}',
6060
'07{{phoneNumber07}}',
61-
'06 ## ## ## ##',
61+
'06 {{phoneNumber06WithSeparator}}',
6262
'07 {{phoneNumber07WithSeparator}}',
6363
];
6464

@@ -73,6 +73,26 @@ class PhoneNumber extends \Faker\Provider\PhoneNumber
7373
'+33#########',
7474
];
7575

76+
public function phoneNumber06()
77+
{
78+
$phoneNumber = $this->phoneNumber06WithSeparator();
79+
80+
return str_replace(' ', '', $phoneNumber);
81+
}
82+
83+
/**
84+
* Only 0601 to 0638, 0640 to 0689, 0695 and 0698 to 0699 are acceptable prefixes with 06
85+
*
86+
* @see https://www.arcep.fr/la-regulation/grands-dossiers-thematiques-transverses/la-numerotation.html#c8961
87+
* @see https://www.itu.int/itu-t/nnp/#/numbering-plans?country=France%C2%A0&code=33
88+
*/
89+
public function phoneNumber06WithSeparator()
90+
{
91+
$regex = '([0-24-8]\d|3[0-8]|9[589])( \d{2}){3}';
92+
93+
return static::regexify($regex);
94+
}
95+
7696
public function phoneNumber07()
7797
{
7898
$phoneNumber = $this->phoneNumber07WithSeparator();
@@ -81,16 +101,16 @@ public function phoneNumber07()
81101
}
82102

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

93-
return $phoneNumber;
113+
return static::regexify($regex);
94114
}
95115

96116
public function phoneNumber08()
@@ -121,9 +141,9 @@ public function phoneNumber08()
121141
*/
122142
public function phoneNumber08WithSeparator()
123143
{
124-
$regex = '([012]{1}\d{1}|(9[1-357-9])( \d{2}){3}';
144+
$regex = '([012]\d|(9[1-357-9])( \d{2}){3}';
125145

126-
return $this->regexify($regex);
146+
return static::regexify($regex);
127147
}
128148

129149
/**

test/Faker/Provider/fr_FR/PhoneNumberTest.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,37 +13,49 @@ final class PhoneNumberTest extends TestCase
1313
public function testMobileNumber(): void
1414
{
1515
$mobileNumber = $this->faker->mobileNumber();
16-
self::assertMatchesRegularExpression('/^(\+33 |\+33 \(0\)|0)(6|7)(?:(\s{1})?\d{2}){4}$/', $mobileNumber);
16+
self::assertMatchesRegularExpression('/^(\+33 |\+33 \(0\)|0)([67])(?:(\s)?\d{2}){4}$/', $mobileNumber);
17+
}
18+
19+
public function testMobileNumber06Format(): void
20+
{
21+
$mobileNumberFormat = $this->faker->phoneNumber06();
22+
self::assertMatchesRegularExpression('/^([0-24-8]\d|3[0-8]|9[589])(\d{2}){3}$/', $mobileNumberFormat);
23+
}
24+
25+
public function testMobileNumber06WithSeparatorFormat(): void
26+
{
27+
$mobileNumberFormat = $this->faker->phoneNumber06WithSeparator();
28+
self::assertMatchesRegularExpression('/^([0-24-8]\d|3[0-8]|9[589])( \d{2}){3}$/', $mobileNumberFormat);
1729
}
1830

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

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

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

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

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

4961
public function testE164PhoneNumberFormat(): void

0 commit comments

Comments
 (0)