diff --git a/src/Rules/Cnpj.php b/src/Rules/Cnpj.php index d6696c8..9d541dd 100644 --- a/src/Rules/Cnpj.php +++ b/src/Rules/Cnpj.php @@ -10,8 +10,12 @@ class Cnpj implements Rule { protected $invalidCnpjs; - public function __construct() + public $allowMask; + + public function __construct($allowMask = true) { + $this->allowMask = $allowMask; + $this->invalidCnpjs = [ '00000000000000', '11111111111111', @@ -32,7 +36,9 @@ public function passes($attribute, $value): bool return true; } - $value = preg_replace('/\D/', '', $value); + if ($this->allowMask) { + $value = preg_replace('/\D/', '', $value); + } if (!($value && mb_strlen($value) === 14)) { return false; diff --git a/src/Rules/Cpf.php b/src/Rules/Cpf.php index 5ddc17e..9dab9bd 100644 --- a/src/Rules/Cpf.php +++ b/src/Rules/Cpf.php @@ -10,8 +10,12 @@ class Cpf implements Rule { protected $invalidCpfs; - public function __construct() + public $allowMask; + + public function __construct($allowMask = true) { + $this->allowMask = $allowMask; + $this->invalidCpfs = [ '00000000000', '11111111111', @@ -32,7 +36,9 @@ public function passes($attribute, $value): bool return true; } - $value = preg_replace('/\D/', '', $value); + if ($this->allowMask) { + $value = preg_replace('/\D/', '', $value); + } if (!($value && mb_strlen($value) === 11)) { return false; diff --git a/src/Rules/Nfe.php b/src/Rules/Nfe.php index 3d6812b..2e280e8 100644 --- a/src/Rules/Nfe.php +++ b/src/Rules/Nfe.php @@ -8,13 +8,22 @@ class Nfe { + public $allowMask; + + public function __construct($allowMask = false) + { + $this->allowMask = $allowMask; + } + public function passes($attribute, $value): bool { if (!$value) { return true; } - $value = preg_replace('/\D/', '', $value); + if ($this->allowMask) { + $value = preg_replace('/\D/', '', $value); + } if (!($value && mb_strlen($value) === 44) || mb_substr($value, 0, 2) === '00') { return false;