Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7247b2a

Browse files
committed
fix CPF validation
1 parentaf568cb commit7247b2a

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

‎src/validator-docs/Rules/Cpf.php‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,27 @@
44

55
namespacegeekcom\ValidatorDocs\Rules;
66

7+
usegeekcom\ValidatorDocs\ValidatorFormats;
8+
79
usefunctionpreg_match;
810
usefunctionmb_strlen;
911

1012
finalclass Cpfextends Sanitization
1113
{
14+
protectedfunctionvalidateFormat($value,$document,$attribute =null)
15+
{
16+
if (!empty($value)) {
17+
return (newValidatorFormats())->execute($value,$document);
18+
}
19+
}
20+
1221
publicfunctionvalidateCpf($attribute,$value):bool
1322
{
23+
24+
if (!$this->validateFormat($value,'cpf')) {
25+
returnfalse;
26+
}
27+
1428
$c =$this->sanitize($value);
1529

1630
if (mb_strlen($c) !=11 ||preg_match("/^{$c[0]}{11}$/",$c)) {

‎src/validator-docs/Validator.php‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,10 @@ public function __construct(
3030
parent::__construct($translator,$data,$rules,$messages,$customAttributes);
3131
}
3232

33-
protectedfunctionvalidateFormat($value,$document,$attribute =null)
34-
{
35-
if (!empty($value)) {
36-
return (newValidatorFormats())->execute($value,$document);
37-
}
38-
}
39-
4033
protectedfunctionvalidateCpf($attribute,$value):bool
4134
{
4235
$cpf =newCpf();
4336

44-
$this->validateFormat($value,'cpf');
45-
4637
return$cpf->validateCpf($attribute,$value);
4738
}
4839

‎tests/TestValidator.php‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,16 @@ public function cpf()
1919
['errado' =>'cpf']
2020
);
2121

22+
$incorrectWithAlpha = Validator::make(
23+
['errado' =>'094.050.986-59ABCDEF'],
24+
['errado' =>'cpf']
25+
);
26+
2227
$this->assertTrue($correct->passes());
2328

2429
$this->assertTrue($incorrect->fails());
30+
31+
$this->assertTrue($incorrectWithAlpha->fails());
2532
}
2633

2734
/** @test **/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp