SA-MP Forums Archive
How to check if there's no symbols in a string? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: How to check if there's no symbols in a string? (/showthread.php?tid=414533)



How to check if there's no symbols in a string? - PaulDinam - 09.02.2013

I have this command:

I need a stock that checks if there is no symbols like this:
!,@,#,$,%,^,&,*,(,),_,+,|,/,.,',;,[,],{,},`
Код:
CMD:changepassword(playerid, params[])
{
	if(sscanf(params,"s[128]",newPassword[playerid]))
	{
		SyntaxMSG(playerid, "/changepass [password]");
		SCM(playerid, -1, "{FF0000}[WARNING]:{FFFFFF} Do not use any {00FF00}symbols{FFFFFF} on your new password.");
		return 1;
	}
	ShowDialog(playerid, Show:<ChangePass>, DIALOG_STYLE_INPUT, "Password changer", "Please enter your secret word that you've registered with!", "Change", "Exit");
	return 1;
}



Re: How to check if there's no symbols in a string? - PaulDinam - 09.02.2013

Okay I found a way, I did this:
Код:
CMD:changepassword(playerid, params[])
{
	if(sscanf(params,"s[128]",newPassword[playerid]))
	{
		SyntaxMSG(playerid, "/changepass [password]");
		SCM(playerid, -1, "{FF0000}[WARNING]:{FFFFFF} Do not use any {00FF00}symbols{FFFFFF} on your new password.");
		return 1;
	}
	for(new i = 0; i < strlen(newPassword[playerid]); i++)
	{
		switch(newPassword[playerid][i])
		{
			case '!', '@', '#', '$','%','^','&','*','(',')','_','+','=','|','[',']','{','}','-','.','`','~','<','>','?',',': return SCM(playerid, 0xFF0000FF, "Invalid characters!");
			default: continue;
		}
	}
	ShowDialog(playerid, Show:<ChangePass>, DIALOG_STYLE_INPUT, "Password changer", "Please enter your secret word that you've registered with!", "Change", "Exit");
	return 1;
}



Re: How to check if there's no symbols in a string? - batonsa - 09.02.2013

EDIT: Good you found your way, since taking foreign scripts into your GM is always a risk.

Maybe something like this
Код:
function CheckPassword(playerid)
 {
	new password[MAX_PLAYER_PASSWORD];
	GetPlayerPassword(playerid, name, MAX_PLAYER_PASSWORD);
	for(new i = 0; i < MAX_PLAYER_PASSWORD; i ++ )
	{
	    if(password[i] == '[' || password[i] == ']' || password[i] == '.' || password[i] == '+' || password[i] == '-' || password[i] == '@' || password[i] == '%' || password[i] == ':' || password[i] == ';' || password[i] == '(' || password[i] == ')' || password[i] == '{' || password[i] == '}' || password[i] == '=' || password[i] == '$') return 0;
	}
	return 0;
}
EDIT: Never mind lol