Skip to content

Commit 963eb00

Browse files
committed
Added a custom validation message
1 parent f716f17 commit 963eb00

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

CHANGELOG.md

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

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

5+
### 1.1.0
6+
- Added a custom validation message
7+
58
### 1.0.0
69
- Initial release and connected with packagist

src/ServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function register()
4040
} else {
4141
return $x->isPhone($value);
4242
}
43-
});
43+
}, "Not a valid phone number");
4444
});
4545
}
4646
}

tests/ValidatorTest.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ public function testItCreatesAnInstanceOfPhoneValidator()
1313
$this->assertInstanceOf(PhoneValidator::class, $obj);
1414
}
1515

16-
protected function validate($color, $rule = 'phone')
16+
protected function validate($number, $rule = 'phone')
1717
{
18-
return !(Validator::make(['test' => $color], ['test' => $rule])->fails());
18+
return !(Validator::make(['attr' => $number], ['attr' => $rule])->fails());
1919
}
2020

2121
public function testValidatorPhone()
@@ -25,11 +25,17 @@ public function testValidatorPhone()
2525

2626
public function testValidatorPhoneE164()
2727
{
28-
$this->assertEquals(true, $this->validate('+15556667777', 'phone:E164'));
28+
$this->assertEquals(true, $this->validate('+15556660000', 'phone:E164'));
2929
$this->assertEquals(false, $this->validate('+1555 ex 1234', 'phone:E164'));
3030
$this->assertEquals(false, $this->validate('+155566677775556667777', 'phone:E164'));
3131
$this->assertEquals(false, $this->validate('+1555', 'phone:E164'));
3232
$this->assertEquals(false, $this->validate('5556667777', 'phone:E164'));
3333
$this->assertEquals(false, $this->validate('+1(555)666-7777', 'phone:E164'));
3434
}
35+
36+
public function testValidatorErrorMessage()
37+
{
38+
$validator = Validator::make(['attr' => '+1555 ex 1234'], ['attr' => 'phone:E164']);
39+
$this->assertEquals("Not a valid phone number", $validator->errors()->first());
40+
}
3541
}

0 commit comments

Comments
 (0)