Skip to content

Commit b833b4e

Browse files
committed
add validateTR into CountryPhoneCallback with test
1 parent 52525c1 commit b833b4e

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/Utils/CountryPhoneCallback.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,16 @@ protected function validateSE()
167167
return preg_match('/^(?:\+46|0) ?(?:[1-9]\d{1,2}-?\d{2}(?:\s?\d{2}){2}|7\d{2}-?\d{2}(?:\s?\d{2}){2})$/', $this->value);
168168
}
169169

170+
/**
171+
* Validate Turkey phone number.
172+
*
173+
* @return false|int
174+
*/
175+
protected function validateTR()
176+
{
177+
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);
178+
}
179+
170180
/**
171181
* Call the phone validator method for each country code and return the results.
172182
*

tests/Rules/ValidPhoneNumberTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public function all_phone_number_is_valid_by_specific_code()
8383
'phone_ko' => [new ValidPhoneNumber(Country::KOREAN)],
8484
'phone_ru' => [new ValidPhoneNumber(Country::RUSSIA)],
8585
'phone_se' => [new ValidPhoneNumber(Country::SWEDEN)],
86+
'phone_tr' => [new ValidPhoneNumber(Country::TURKEY)],
8687
];
8788
$data = [
8889
'phone_ir' => '09125555555',
@@ -100,6 +101,7 @@ public function all_phone_number_is_valid_by_specific_code()
100101
'phone_ko' => '+821012345678',
101102
'phone_ru' => '+79101234567',
102103
'phone_se' => '+46701234567',
104+
'phone_tr' => '+905551234567',
103105
];
104106
$passes = $this->app['validator']->make($data, $rules)->passes();
105107

0 commit comments

Comments
 (0)