Skip to content

Commit 00e2c7f

Browse files
authored
Merge pull request #141 from cauafroes/feature/passaporte-validacao
suporte validação passaporte
2 parents 5460d4a + 4149012 commit 00e2c7f

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace geekcom\ValidatorDocs\Rules;
6+
7+
final class Passaporte extends Sanitization
8+
{
9+
public function validatePassaporte($attribute, $value): bool
10+
{
11+
return preg_match('/^[A-Za-z]{2}\d{6}$/i', $value) > 0;
12+
}
13+
}

src/validator-docs/Validator.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
Nis,
1313
Placa,
1414
Renavam,
15-
TituloEleitoral};
15+
TituloEleitoral,
16+
Passaporte};
1617
use Illuminate\Contracts\Translation\Translator;
1718
use Illuminate\Validation\Validator as BaseValidator;
1819

@@ -122,4 +123,10 @@ protected function validateDdd($attribute, $value): bool
122123

123124
return $ddd->validateDdd($attribute, $value);
124125
}
126+
127+
protected function validatePassaporte($attribute, $value): bool
128+
{
129+
$passaporte = new Passaporte();
130+
return $passaporte->validatePassaporte($attribute, $value);
131+
}
125132
}

src/validator-docs/ValidatorProvider.php

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ protected function getMessages()
4949
'certidao' => 'Número da Certidão inválido',
5050
'ddd' => 'DDD inválido',
5151
'placa' => 'Placa inválida',
52+
'passaporte' => 'Passaporte inválido',
5253
'formato_cnpj' => 'Formato inválido para CNPJ',
5354
'formato_cpf' => 'Formato inválido para CPF',
5455
'formato_cpf_cnpj' => 'Formato inválido para CPF ou CNPJ',

tests/TestValidator.php

+17
Original file line numberDiff line numberDiff line change
@@ -341,4 +341,21 @@ public function ddd()
341341

342342
$this->assertTrue($incorrect->fails());
343343
}
344+
345+
/** @test **/
346+
public function passaporte()
347+
{
348+
$correct = Validator::make(
349+
['certo' => 'GB139485'],
350+
['certo' => 'passaporte']
351+
);
352+
353+
$incorrect = Validator::make(
354+
['errado' => 'A3948'],
355+
['errado' => 'passaporte']
356+
);
357+
358+
$this->assertTrue($correct->passes());
359+
$this->assertTrue($incorrect->fails());
360+
}
344361
}

0 commit comments

Comments
 (0)