Skip to content

Commit c38ea62

Browse files
committed
add validateZH into CountryPhoneCallback with test
1 parent b833b4e commit c38ea62

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

src/Utils/Country.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ class Country
4242

4343
public const CHAD = 'TD';
4444

45+
public const CHINA = 'zh';
46+
4547
public const COMOROS = 'KM';
4648

4749
public const CONGO = 'CG';

src/Utils/CountryPhoneCallback.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,16 @@ protected function validateTR()
177177
return preg_match('/^(?:\+90|0)(?:\s?[1-9]\d{2}\s?\d{3}\s?\d{2}\s?\d{2}|[1-9]\d{2}-?\d{3}-?\d{2}-?\d{2})$/', $this->value);
178178
}
179179

180+
/**
181+
* Validate Chinese phone number.
182+
*
183+
* @return false|int
184+
*/
185+
protected function validateZH()
186+
{
187+
return preg_match('/^(?:\+86)?1[3-9]\d{9}$/', $this->value);
188+
}
189+
180190
/**
181191
* Call the phone validator method for each country code and return the results.
182192
*

tests/Rules/ValidPhoneNumberTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public function all_phone_number_is_valid_by_specific_code()
8484
'phone_ru' => [new ValidPhoneNumber(Country::RUSSIA)],
8585
'phone_se' => [new ValidPhoneNumber(Country::SWEDEN)],
8686
'phone_tr' => [new ValidPhoneNumber(Country::TURKEY)],
87+
'phone_ch' => [new ValidPhoneNumber(Country::CHINA)],
8788
];
8889
$data = [
8990
'phone_ir' => '09125555555',
@@ -102,6 +103,7 @@ public function all_phone_number_is_valid_by_specific_code()
102103
'phone_ru' => '+79101234567',
103104
'phone_se' => '+46701234567',
104105
'phone_tr' => '+905551234567',
106+
'phone_ch' => '+8613812345678',
105107
];
106108
$passes = $this->app['validator']->make($data, $rules)->passes();
107109

0 commit comments

Comments
 (0)