summaryrefslogtreecommitdiff
path: root/src/application/mystic/forum/utils/ValidationUtils.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/application/mystic/forum/utils/ValidationUtils.php')
-rw-r--r--src/application/mystic/forum/utils/ValidationUtils.php22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/application/mystic/forum/utils/ValidationUtils.php b/src/application/mystic/forum/utils/ValidationUtils.php
new file mode 100644
index 0000000..df97914
--- /dev/null
+++ b/src/application/mystic/forum/utils/ValidationUtils.php
@@ -0,0 +1,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");
+ }
+}
+