This commit is contained in:
39
api/app/Rules/NomeCompleto.php
Normal file
39
api/app/Rules/NomeCompleto.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rules;
|
||||
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
|
||||
class NomeCompleto implements Rule
|
||||
{
|
||||
/**
|
||||
* Determine if the validation rule passes.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function passes($attribute, $value)
|
||||
{
|
||||
return self::isValid($value);
|
||||
}
|
||||
|
||||
public static function isValid($value)
|
||||
{
|
||||
|
||||
$chars = "A-ZÁÉÍÓÚÂÊÎÔÛÃÕÄËÏÖÜÇ'";
|
||||
$regex = "/^[" . $chars . "]{2,}\s([" . $chars . "]{1,}\s?)*[" . $chars . "]{2,}$/";
|
||||
|
||||
return !!preg_match($regex, trim($value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation error message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function message()
|
||||
{
|
||||
return 'Nome e Sobrenome inválidos.';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user