Skip to content

Commit

Permalink
Extract mask chars before validate
Browse files Browse the repository at this point in the history
  • Loading branch information
wemersonrv committed May 18, 2019
1 parent e60457f commit d50db25
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ if($validator->fails()){

## Release History

* 0.3.1
* Sanitize value before validation
* CHANGE: Extract only digits (without mask chars) to validate
* 0.3.0
* Brazilian CNPJ
* ADD: Brazilian CNPJ rule (`cnpj`)
Expand Down
3 changes: 3 additions & 0 deletions src/Rules/Cnpj.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class Cnpj implements Rule
public function passes($attribute, $value)
{
if(!$value) return true; // Vazio, sem required antes

$value = preg_replace("/\D+/", "", $value); // Limpa máscara ( se houver )

$digitsPattern = '/\d{14}/'; // Regex Padrão de 14 dígitos numéricos
$repeatPattern = '/(\d)\1{13}/'; // regex Padrões repetidos: 00000000000000 11111111111111 etc

Expand Down
3 changes: 3 additions & 0 deletions src/Rules/Cpf.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class Cpf implements Rule
public function passes($attribute, $value)
{
if(!$value) return true; // Vazio, sem required antes

$value = preg_replace("/\D+/", "", $value); // Limpa máscara ( se houver )

$digitsPattern = '/\d{11}/'; // Regex Padrão de 11 dígitos numéricos
$repeatPattern = '/(\d)\1{10}/'; // regex Padrões repetidos: 00000000000 11111111111 etc

Expand Down
3 changes: 3 additions & 0 deletions src/Rules/MobileBr.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class MobileBr implements Rule
public function passes($attribute, $value)
{
if(!$value) return true; // Vazio, sem required antes

$value = preg_replace("/\D+/", "", $value); // Limpa máscara ( se houver )

$digitsPattern = '/\d{11}/'; // Regex Padrão de 11 dígitos numéricos
$repeatPattern = '/(\d)\1{10}/'; // regex Padrões repetidos: 00000000000 11111111111 etc

Expand Down

0 comments on commit d50db25

Please sign in to comment.