Skip to content

Commit 3c70903

Browse files
committed
Empty values are now valid
1 parent 963eb00 commit 3c70903

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
All notable changes to `laravel-validator-phone` will be documented in this file.
44

5+
### 1.1.1
6+
- Empty values are now valid phone numbers (You should be using the 'required' validation rule when checking for non empty values)
7+
58
### 1.1.0
69
- Added a custom validation message
710

src/Validator.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@
44

55
class Validator
66
{
7-
public function isPhone($value)
7+
public function __call($a, $b)
8+
{
9+
return empty($b[0]) || $this->{$a}($b[0]);
10+
}
11+
12+
protected function isPhone($value)
813
{
914
return $this->isE164($value);
1015
}
1116

12-
public function isE164($value)
17+
protected function isE164($value)
1318
{
1419
$conditions = [];
1520
$conditions[] = strpos($value, "+") === 0;

tests/ValidatorTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ public function testValidatorPhone()
2323
$this->assertEquals(true, $this->validate('+15556667777', 'phone'));
2424
}
2525

26+
public function testValidatorWithEmpty()
27+
{
28+
$this->assertEquals(true, $this->validate('', 'phone'));
29+
$this->assertEquals(true, $this->validate(null, 'phone'));
30+
$this->assertEquals(true, $this->validate([], 'phone'));
31+
$this->assertEquals(true, $this->validate(false, 'phone'));
32+
}
33+
2634
public function testValidatorPhoneE164()
2735
{
2836
$this->assertEquals(true, $this->validate('+15556660000', 'phone:E164'));

0 commit comments

Comments
 (0)