-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathLabel.php
More file actions
39 lines (33 loc) · 862 Bytes
/
Label.php
File metadata and controls
39 lines (33 loc) · 862 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
31
32
33
34
35
36
37
38
39
<?php
namespace Utopia\Database\Validator;
use Utopia\Database\Database;
class Label extends Key
{
public function __construct(
bool $allowInternal = false,
int $maxLength = Database::MAX_UID_DEFAULT_LENGTH
) {
parent::__construct($allowInternal, $maxLength);
$this->message = 'Value must be a valid string between 1 and ' . $this->maxLength . ' chars containing only alphanumeric chars';
}
/**
* Is valid.
*
* Returns true if valid or false if not.
*
* @param $value
*
* @return bool
*/
public function isValid($value): bool
{
if (!parent::isValid($value)) {
return false;
}
// Valid chars: A-Z, a-z, 0-9
if (\preg_match('/[^A-Za-z0-9]/', $value)) {
return false;
}
return true;
}
}