-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathFullName.php
More file actions
executable file
·30 lines (24 loc) · 882 Bytes
/
FullName.php
File metadata and controls
executable file
·30 lines (24 loc) · 882 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
declare(strict_types=1);
namespace Sirius\Validation\Rule;
class FullName extends AbstractRule
{
const MESSAGE = 'This input is not a valid full name (first name and last name)';
const LABELED_MESSAGE = '{label} is not a valid full name (first name and last name)';
/**
* This is not going to work with Asian names, http://en.wikipedia.org/wiki/Chinese_name.
*/
public function validate(mixed $value, ?string $valueIdentifier = null): bool
{
$this->value = $value;
$names = explode(' ', $value);
// Each name must be at least 2 characters long.
foreach ($names as $name) {
if (mb_strlen($name) < 2) {
return $this->success = false;
}
}
// Name cannot be longer shorter than 6 characters.
return $this->success = mb_strlen($value) >= 6;
}
}