BrainCMS - preg_match register username

Status
Not open for further replies.
Dec 17, 2017
151
19
Hi Devbest,

in my register.php it is not possible to register username with .,- or special characters. Only letters are allowed.

Which file should I change?

Thanks a lot to those who will help me :)
 

Joe

Well-Known Member
Jun 10, 2012
4,090
1,918
It'll be in the config somewhere for the BrainCMS engine, I could help you a lot more if it was RevCMS, I've never used Brain :p
 

Higoka

Active Member
Dec 16, 2018
174
74
In "/system/app/classes/class.user.php" replace the function validName with this one.
PHP:
public static function validName($username)
{
    return preg_match('~^[a-z0-9.,-]{3,12}$~i', $username);
}

Username must be between 3 and 12 characters long and you should be allowed to use letters, numbers and these special chars: . , -
Didn't test it but should work.
 
Dec 17, 2017
151
19
In "/system/app/classes/class.user.php" replace the function validName with this one.
PHP:
public static function validName($username)
{
    return preg_match('~^[a-z0-9.,-]{3,12}$~i', $username);
}

Username must be between 3 and 12 characters long and you should be allowed to use letters, numbers and these special chars: . , -
Didn't test it but should work.
Thanks for reply :)

Code now is
PHP:
        public static function validName($username)
        {
            if(strlen($username) <= 12 && strlen($username) >= 3 && ctype_alnum($username))
            {
                return true;
            }
            return false;
        }
How should it become?
Post automatically merged:

Problem solved, thanks to @Higoka
 
Last edited:
Dec 17, 2017
151
19
Can you post the code that worked for other people having a similar problem?
Yes, sorry. :)

Replace
PHP:
        public static function validName($username)
        {
            if(strlen($username) <= 12 && strlen($username) >= 3 && ctype_alnum($username))
            {
                return true;
            }
            return false;
        }

To
PHP:
        public static function validName($username)
        {
            if(preg_match('~^[a-z0-9.,-]{3,12}$~i', $username))
            {
                return true;
            }
            return false;
        }
 
  • Like
Reactions: Joe
Status
Not open for further replies.

Users who are viewing this thread

Top