Username requirement adjustments.
This commit is contained in:
parent
c4222eed71
commit
a3ccbd8bf0
2 changed files with 7 additions and 1 deletions
|
@ -15,6 +15,7 @@ class AuthController extends Controller
|
||||||
'trim' => 'Your username may not start or end with spaces!',
|
'trim' => 'Your username may not start or end with spaces!',
|
||||||
'short' => "Your username is too short, it has to be at least " . User::USERNAME_MIN_LENGTH . " characters!",
|
'short' => "Your username is too short, it has to be at least " . User::USERNAME_MIN_LENGTH . " characters!",
|
||||||
'long' => "Your username is too long, it can't be longer than " . User::USERNAME_MAX_LENGTH . " characters!",
|
'long' => "Your username is too long, it can't be longer than " . User::USERNAME_MAX_LENGTH . " characters!",
|
||||||
|
'double-spaces' => "Your username can't contain double spaces.",
|
||||||
'invalid' => 'Your username contains invalid characters.',
|
'invalid' => 'Your username contains invalid characters.',
|
||||||
'spacing' => 'Please use either underscores or spaces, not both!',
|
'spacing' => 'Please use either underscores or spaces, not both!',
|
||||||
];
|
];
|
||||||
|
|
|
@ -14,6 +14,7 @@ class User extends Model
|
||||||
|
|
||||||
public const USERNAME_MIN_LENGTH = 3;
|
public const USERNAME_MIN_LENGTH = 3;
|
||||||
public const USERNAME_MAX_LENGTH = 16;
|
public const USERNAME_MAX_LENGTH = 16;
|
||||||
|
public const USERNAME_REGEX = '#^[A-Za-z0-9-_ ]+$#u';
|
||||||
|
|
||||||
protected $primaryKey = 'user_id';
|
protected $primaryKey = 'user_id';
|
||||||
|
|
||||||
|
@ -55,7 +56,11 @@ class User extends Model
|
||||||
return 'long';
|
return 'long';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strpos($username, ' ') !== false || !preg_match('#^[A-Za-z0-9-\[\]_ ]+$#u', $username)) {
|
if (strpos($username, ' ') !== false) {
|
||||||
|
return 'double-spaces';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!preg_match(self::USERNAME_REGEX, $username)) {
|
||||||
return 'invalid';
|
return 'invalid';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue