Only numbers in dialog/inputtext
#1

Hi,
So as title say, how i can set players can type only numbers in dialog(or if he type letter to show him message).

Код:
 if(dialogid == DGODINE){
        if(!response) return KickWithMessage(playerid, RED, "Morate unijeti godine kako biste se registrovali(Kickovani ste!)");
        if(response){
            if(!strlen(inputtext) || strlen(inputtext) >= 40 || strlen(inputtext) <= 10 ) {
                SendClientMessage(playerid, RED, "Morate unijeti godine kako biste nastavili registraciju(Ne mozete imati manje od 10 ili vise od 40 godina)");
                new str[512],str2[512];
                format(str,sizeof(str),""GOLD"Divante Roleplay - "SPLAVA"Godine");
                format(str2,sizeof(str2),""BIJELA"Unesite godine ispod");
                ShowPlayerDialog(playerid, DGODINE, DIALOG_STYLE_INPUT,str, str2, "Uredu","Izadji");
                return 1;
            }
            PlayerTextDrawSetString(playerid, registracija[7][playerid], inputtext);
            return 1;
        }
    }
Reply
#2

pawn Код:
IsNumeric(const string[])
{
    for (new i = 0, j = strlen(string); i < j; i++)
    {
        if (string[i] > '9' || string[i] < '0') return 0;
    }
    return 1;
}
Reply
#3

Код:
stock isnumeric(str[])
{
	new
		ch,
		i;
	while ((ch = str[i++])) if (!('0' <= ch <= '9')) return 0;
	return 1;
}

if(!strlen(inputtext) || strlen(inputtext) >= 40 || strlen(inputtext) <= 10 || !isnumeric(inputtext))
Reply
#4

You can simply use IsNumeric. It only allows to write numbers.
Reply
#5

Or, if you're already using sscanf you can use its "quiet" option for type checking without the need for an extra function. But most of the time you do need to store what was entered and so this also saves you the use of strval.

pawn Код:
if(sscanf(inputtext, "{i}"))
Reply
#6

Thanks all, it works!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)