06.06.2008, 01:27
CheckPlayerName - checks a string to ensure it follows the traditional Firstname_Lastname roleplay name format
Returns:
0 - Invalid roleplay name
1 - Valid roleplay name
Returns:
0 - Invalid roleplay name
1 - Valid roleplay name
pawn Code:
CheckPlayerName(const name[]) // by Luk0r
{
if (strlen(name) < 6) return 0;
if (strfind(name, "_", true) == -1) return 0;
new underscorecount, expectinguppercase = 1;
for (new i = 0, j = strlen(name); i < j; i++)
{
if (expectinguppercase == 1)
{
if (name[i] < 'A' || name[i] > 'Z') return 0;
expectinguppercase = 0;
continue;
}
switch (name[i])
{
case '_':
{
if (underscorecount == 1) return 0;
else
{
underscorecount = 1;
expectinguppercase = 1;
}
continue;
}
case 'A' .. 'Z': continue;
case 'a' .. 'z': continue;
default: return 0;
}
}
return 1;
}