Check username format.
#1

How would I go on about checking username format? So basically if username is in First_Last formart and if there is any numbers in the name?
Reply
#2

I'd use sscanf and strfind:
pawn Код:
public OnPlayerConnect(playerid)
{
    new
        name[24],
        string[2];
       
    GetPlayerName(playerid, name, sizeof(name)); // we need player's name
    if(sscanf(name, "{p<_>s[12]s[12]}") != 0) // we check if there is a delimiter "_" splitting two strings (name and lastname)
    {
        SendClientMessage(playerid, 0xFFFFFFFF, "* You have been banned because your nickname didn't have a \"_\"!");
        Ban(playerid); // we ban the player if there was no "_"
    }
    for(new i = 0; i < 10; i ++) // we make a loop from 0 to 9
    {
        format(string, sizeof(string), "%d", i); // we set "i" (the number being worked) to the string
        if(strfind(name, string, true) != -1) // is there any number in "name"?
        {
            SendClientMessage(playerid, 0xFFFFFFFF, "* You have been banned because your nickname had a number!");
            Ban(playerid); // if yes then BAN!!!!!!    
        }
    }
    return 1;
}
Reply
#3

Lol Miguel nice code there but you don't need to ban someone for those reasons do you
Reply
#4

oh my god hahahahahah !!
Reply
#5

And instead of formatting, you could just use valstr
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)