diff --git a/src/pt-br-validator/Rules/CelularComCodigoSemMascara.php b/src/pt-br-validator/Rules/CelularComCodigoSemMascara.php new file mode 100644 index 0000000..365d9c4 --- /dev/null +++ b/src/pt-br-validator/Rules/CelularComCodigoSemMascara.php @@ -0,0 +1,30 @@ + +*/ +class CelularComCodigoSemMascara implements Rule +{ + + + /** + * Valida o formato do celular com código do país + * + * @param string $attribute + * @param string $value + * @return boolean + */ + public function passes($attribute, $value) + { + return preg_match('/^[+]\d{1,2}\s?\d{2}\s?\d{4,5}\d{4}$/', $value) > 0; + } + + public function message() + { + return 'O campo :attribute não é um celular válido. Exemplo de celular válido +5514999999999'; + } +} \ No newline at end of file diff --git a/src/pt-br-validator/ValidatorProvider.php b/src/pt-br-validator/ValidatorProvider.php index 92a97cb..6394c83 100755 --- a/src/pt-br-validator/ValidatorProvider.php +++ b/src/pt-br-validator/ValidatorProvider.php @@ -24,25 +24,26 @@ class ValidatorProvider extends ServiceProvider public function boot() { $rules = [ - 'celular' => \LaravelLegends\PtBrValidator\Rules\Celular::class, - 'celular_com_ddd' => \LaravelLegends\PtBrValidator\Rules\CelularComDdd::class, - 'celular_com_codigo' => \LaravelLegends\PtBrValidator\Rules\CelularComCodigo::class, - 'cnh' => \LaravelLegends\PtBrValidator\Rules\Cnh::class, - 'cnpj' => \LaravelLegends\PtBrValidator\Rules\Cnpj::class, - 'cns' => \LaravelLegends\PtBrValidator\Rules\Cns::class, - 'cpf' => \LaravelLegends\PtBrValidator\Rules\Cpf::class, - 'formato_cnpj' => \LaravelLegends\PtBrValidator\Rules\FormatoCnpj::class, - 'formato_cpf' => \LaravelLegends\PtBrValidator\Rules\FormatoCpf::class, - 'telefone' => \LaravelLegends\PtBrValidator\Rules\Telefone::class, - 'telefone_com_ddd' => \LaravelLegends\PtBrValidator\Rules\TelefoneComDdd::class, - 'telefone_com_codigo' => \LaravelLegends\PtBrValidator\Rules\TelefoneComCodigo::class, - 'formato_cep' => \LaravelLegends\PtBrValidator\Rules\FormatoCep::class, - 'formato_placa_de_veiculo' => \LaravelLegends\PtBrValidator\Rules\FormatoPlacaDeVeiculo::class, - 'formato_pis' => \LaravelLegends\PtBrValidator\Rules\FormatoPis::class, - 'pis' => \LaravelLegends\PtBrValidator\Rules\Pis::class, - 'cpf_ou_cnpj' => \LaravelLegends\PtBrValidator\Rules\CpfOuCnpj::class, - 'formato_cpf_ou_cnpj' => \LaravelLegends\PtBrValidator\Rules\FormatoCpfOuCnpj::class, - 'uf' => \LaravelLegends\PtBrValidator\Rules\Uf::class, + 'celular' => \LaravelLegends\PtBrValidator\Rules\Celular::class, + 'celular_com_ddd' => \LaravelLegends\PtBrValidator\Rules\CelularComDdd::class, + 'celular_com_codigo' => \LaravelLegends\PtBrValidator\Rules\CelularComCodigo::class, + 'celular_com_codigo_sem_mascara' => \LaravelLegends\PtBrValidator\Rules\CelularComCodigoSemMascara::class, + 'cnh' => \LaravelLegends\PtBrValidator\Rules\Cnh::class, + 'cnpj' => \LaravelLegends\PtBrValidator\Rules\Cnpj::class, + 'cns' => \LaravelLegends\PtBrValidator\Rules\Cns::class, + 'cpf' => \LaravelLegends\PtBrValidator\Rules\Cpf::class, + 'formato_cnpj' => \LaravelLegends\PtBrValidator\Rules\FormatoCnpj::class, + 'formato_cpf' => \LaravelLegends\PtBrValidator\Rules\FormatoCpf::class, + 'telefone' => \LaravelLegends\PtBrValidator\Rules\Telefone::class, + 'telefone_com_ddd' => \LaravelLegends\PtBrValidator\Rules\TelefoneComDdd::class, + 'telefone_com_codigo' => \LaravelLegends\PtBrValidator\Rules\TelefoneComCodigo::class, + 'formato_cep' => \LaravelLegends\PtBrValidator\Rules\FormatoCep::class, + 'formato_placa_de_veiculo' => \LaravelLegends\PtBrValidator\Rules\FormatoPlacaDeVeiculo::class, + 'formato_pis' => \LaravelLegends\PtBrValidator\Rules\FormatoPis::class, + 'pis' => \LaravelLegends\PtBrValidator\Rules\Pis::class, + 'cpf_ou_cnpj' => \LaravelLegends\PtBrValidator\Rules\CpfOuCnpj::class, + 'formato_cpf_ou_cnpj' => \LaravelLegends\PtBrValidator\Rules\FormatoCpfOuCnpj::class, + 'uf' => \LaravelLegends\PtBrValidator\Rules\Uf::class, ]; foreach ($rules as $name => $class) {