-1

So users have been creating accounts and some includes %20, how do I get the input to only accept a-z, A-Z, and 0-9?

if ($username === null){$registrable = false; array_push($error,'Not a valid Username.');}

Can it be similar to the code above?

2 Answers2

0

Are you using a normal text input? If so you can try using pattern="[a-zA-Z0-9-]+" on the input. If the pattern is not correct when submitting the form, users will get a message asking them to use the propper pattern.

Ibai A.
  • 116
  • 1
0

use in php ctype_alnum

if (ctype_alnum($username)) {
    echo "username is aplphanumeric!\n";
} else {
    echo "The usename $username is not valid\n";
}
nbk
  • 45,398
  • 8
  • 30
  • 47