<?php
class ValidateForms{
# Min and Max values for username and passoword
const MIN_USERNAME = 4;
const MAX_USERNAME = 20;
const MIN_PASSWORD = 8;
const MAX_PASSWORD = 40;
# Regex
const REGEX_USERNAME = "/^[A-z0-9_]{" . self::MIN_USERNAME . "," . self::MAX_USERNAME .'}$/';
const REGEX_PASSWORD = "/^[A-z0-9_\\\*\-]{" . self::MIN_PASSWORD . "," . self::MAX_PASSWORD .'}$/';
public static $errors = array(
'username' => array(false, "Invalid username: it must have between {self::MIN_USERNAME} and self::MAX_USERNAME chars."),
'password' => array(false, "Invalid password: it must have between self::MIN_PASSWORD and self::MAX_PASSWORD chars and special chars.")
);
}
print_r(ValidateForms::$errors);
?>
Array
(
[username] => Array
(
[0] =>
[1] => Invalid username: it must have between {self::MIN_USERNAME} and self::MAX_USERNAME chars.
)
[password] => Array
(
[0] =>
[1] => Invalid password: it must have between self::MIN_PASSWORD and self::MAX_PASSWORD chars and special chars.
)
)
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
Array
(
[username] => Array
(
[0] =>
[1] => Invalid username: it must have between {self::MIN_USERNAME} and self::MAX_USERNAME chars.
)
[password] => Array
(
[0] =>
[1] => Invalid password: it must have between self::MIN_PASSWORD and self::MAX_PASSWORD chars and special chars.
)
)