diff --git a/README.md b/README.md index ffefffb..927ddda 100644 --- a/README.md +++ b/README.md @@ -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`) diff --git a/src/Rules/Cnpj.php b/src/Rules/Cnpj.php index 0d6af75..b8f918e 100644 --- a/src/Rules/Cnpj.php +++ b/src/Rules/Cnpj.php @@ -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 diff --git a/src/Rules/Cpf.php b/src/Rules/Cpf.php index 44885a8..dd2fb2a 100644 --- a/src/Rules/Cpf.php +++ b/src/Rules/Cpf.php @@ -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 diff --git a/src/Rules/MobileBr.php b/src/Rules/MobileBr.php index 188056b..c16ce15 100644 --- a/src/Rules/MobileBr.php +++ b/src/Rules/MobileBr.php @@ -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