How to check if player entered an email
#1

Hey guys, how can I check if the player entered an email? I want to restrict a field to emails so they can't type random things.
Reply
#2

Search .. https://sampforum.blast.hk/showthread.php?tid=626317
Reply
#3

http://forum.sa-mp.com/showpost.php?...75&postcount=5
Reply
#4

Quote:
Originally Posted by Sreyas
Посмотреть сообщение
And how should I use those numbers?
Код:
"{s[256]'@'s[256]'.'s[256]}"
Reply
#5

Bump, anyone? How can I use those numbers?
Код:
 "{s[256]'@'s[256]'.'s[256]}"
I want to check if the player entered an email, I mean to only allow emails in a dialog.
Reply
#6

Код:
if(!sscanf(inputtext, "{s[256]'@'s[256]'.'s[256]}")) 
{
	// the email is valid depends on those patterns...
}
Or you can write a function to make it easier to use if you want to call it multiple times.
Код:
IsValidEmail(text[]) // It will return true if text[] is a valid email, it will return false otherwise.
{
	return !sscanf(text, "{s[256]'@'s[256]'.'s[256]}");
}
Reply
#7

Quote:
Originally Posted by X337
Посмотреть сообщение
Код:
if(!sscanf(inputtext, "{s[256]'@'s[256]'.'s[256]}")) 
{
	// the email is valid depends on those patterns...
}
Or you can write a function to make it easier to use if you want to call it multiple times.
Код:
IsValidEmail(text[]) // It will return true if text[] is a valid email, it will return false otherwise.
{
	return !sscanf(text, "{s[256]'@'s[256]'.'s[256]}");
}
It doesn't work, it continues to the next dialog even if I type a normal email or not.

Код:
case DIALOG_EMAIL:
		{
		    if(response)
		    {
                if(!sscanf(inputtext, "{s[256]'@'s[256]'.'s[256]}"))
                {
                    ShowPlayerDialog(playerid, DIALOG_EMAIL, DIALOG_STYLE_INPUT, "{FFA500}E-MAIL", "{FFFFFF}Please enter your email below:\n\n", "NEXT", "");
				}
				else
				{
				    new DB_Query[225];
			        new pName[24];
			        GetPlayerName(playerid, pName, sizeof(pName));
			        format(PlayerInfo[playerid][pEmail],64, "%s", inputtext);
					mysql_format(Database, DB_Query, sizeof(DB_Query), "UPDATE `USERS` SET `email` = '%e' WHERE `USERNAME` = '%e'"
					, PlayerInfo[playerid][pEmail], pName);
					mysql_tquery(Database, DB_Query);

					SendClientMessage(playerid, COLOR_GREEN, "Email set succesfully! Moving onto the next part, gender!");

					ShowPlayerDialog(playerid, DIALOG_SEX, DIALOG_STYLE_MSGBOX, "{FFA500}GENDER", "{FFFFFF}Are you a boy or a girl?\n\n", "BOY", "GIRL");
				}
			}
		}
Reply
#8

Quote:
Originally Posted by AndreiWow
Посмотреть сообщение
It doesn't work, it continues to the next dialog even if I type a normal email or not.

Код:
case DIALOG_EMAIL:
		{
		    if(response)
		    {
                if(!sscanf(inputtext, "{s[256]'@'s[256]'.'s[256]}"))
                {
                    ShowPlayerDialog(playerid, DIALOG_EMAIL, DIALOG_STYLE_INPUT, "{FFA500}E-MAIL", "{FFFFFF}Please enter your email below:\n\n", "NEXT", "");
				}
				else
				{
				    new DB_Query[225];
			        new pName[24];
			        GetPlayerName(playerid, pName, sizeof(pName));
			        format(PlayerInfo[playerid][pEmail],64, "%s", inputtext);
					mysql_format(Database, DB_Query, sizeof(DB_Query), "UPDATE `USERS` SET `email` = '%e' WHERE `USERNAME` = '%e'"
					, PlayerInfo[playerid][pEmail], pName);
					mysql_tquery(Database, DB_Query);

					SendClientMessage(playerid, COLOR_GREEN, "Email set succesfully! Moving onto the next part, gender!");

					ShowPlayerDialog(playerid, DIALOG_SEX, DIALOG_STYLE_MSGBOX, "{FFA500}GENDER", "{FFFFFF}Are you a boy or a girl?\n\n", "BOY", "GIRL");
				}
			}
		}
you mismatched condition....
Reply
#9

Quote:
Originally Posted by Sreyas
Посмотреть сообщение
you mismatched condition....
I tried to enter a simple text like "name" and I also tried a normal email like "email@gmail.com" both worked, there was no restriction... can you show me a right example.
Reply
#10

I haven't checked with your codes but from what I've seen as the format for sscanf used, I assume quiet-specifiers on sscanf requires SSCANF_QUIET mode to be enabled. You can enable it for a single sscanf call though:
pawn Код:
sscanf(inputtext, "?<SSCANF_QUIET=1>{s[256]'@'s[256]'.'s[256]}")
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)