summaryrefslogtreecommitdiff
path: root/src/application/mystic/forum/utils/ValidationUtils.php
blob: df97914e16524b3e42a8b22b454722699d43e890 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
declare(strict_types=1);

namespace mystic\forum\utils;

use mystic\forum\Database;
use mystic\forum\orm\User;

final class ValidationUtils {
    use StaticClass;

    public static function isUsernameValid(string $name): bool {
        return !!preg_match('/^[a-z0-9]([._](?![._])|[a-z0-9]){2,30}[a-z0-9]$/', $name);
    }

    public static function isUsernameAvailable(Database &$db, string $name): bool {
        $user = new User();
        $user->name = $name;
        return !$db->fetchWhere($user, "name");
    }
}