Mysidia Adoptables Support Forum

Mysidia Adoptables Support Forum (http://www.mysidiaadoptables.com/forum/index.php)
-   Questions and Supports (http://www.mysidiaadoptables.com/forum/forumdisplay.php?f=18)
-   -   Disable certain characters in usernames (http://www.mysidiaadoptables.com/forum/showthread.php?t=4936)

Abronsyth 12-16-2015 05:36 PM

Disable certain characters in usernames
 
Resolved

Hello!

So despite the very obvious warning I put on my registration page I still have users registering with special characters in their usernames, which makes it so that their profiles become unviewable and makes for some issues.

Is there a way to disable it so that if they attempt to register with a special character in the username it won't register them, but instead gives the warning "Sorry, please only use letters, numbers, or spaces in your username."

Abronsyth 02-18-2016 11:35 AM

OK, so there's this chunk of code;
Code:

      if($username == "SYSTEM"){
        $this->seterror("Cannot use SYSTEM as username.");
        return FALSE;
      }

But I'm wondering if I could do something like this to make it so the only characters that can be entered are alphanumeric and spaces? So if a user tries something like; "user_name" then they'll get the error; "Sorry, you cannot use special characters in your username."

Some folks use this sort of code;
PHP Code:

if(preg_match('/^[a-zA-Z0-9 ]+$/'$username)) {


Do y'all think I'd be able to incorporate that somehow..?

pachoofoosh 02-18-2016 04:36 PM

To check that usernames only have letters, numbers, and spaces, find the usernamevalidate() function in classes/class_registervalidator.php and replace the function with this:
PHP Code:

protected function usernamevalidate($username ""){
      
// The username validator, note its a bit complicate here due to the different mechanism of username check for register and other validators
      
$lang Registry::get("lang");
      if(!
$this->emptyvalidate($username)){
         
$this->seterror("The field Username is Empty.");
         return 
FALSE;
      }
      if(
preg_match('#^[A-Z0-9 ]+$#i'$username) == FALSE){
         
$this->seterror("Usernames can only contain letters, numbers, and spaces.");
         return 
FALSE;
      }
      
$username = (empty($username))?$this->value['username']:$username;      
      
$userexist $this->datavalidate("users", array("username"), "username = '{$username}'");
      if(
$userexist == TRUE){
         
$this->seterror($lang->user);
         return 
FALSE;
      }
      else return 
TRUE;
  } 


Abronsyth 02-18-2016 06:38 PM

Awesome, thank you!

Also- Pachooooo! <3


All times are GMT -5. The time now is 08:36 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.