Small question
#1

I have an input dialog and I would like to know how I can make the dialog input restricted to numeric only.
Reply
#2

//EDIT: doing it that way is outdated and slow, do it like Konstantinos said guys

its been months since i coded that, ill share it with u:

Код:
stock CheckString(input[],Type)
{
	new result;
	switch(Type)
	{
		case 1://Only numbers and letters allowed
		{
		if(strfind(input, "." ) != -1 || strfind(input, "," ) != -1 || strfind(input, ";" ) != -1 || strfind(input, ":" ) != -1 ||
		strfind(input, "?" ) != -1 || strfind(input, "!" ) != -1 || strfind(input, "Я" ) != -1 || strfind(input, "'" ) != -1 ||
		strfind(input, "-" ) != -1 || strfind(input, "_" ) != -1 || strfind(input, "/" ) != -1 || strfind(input, "(" ) != -1 ||
		strfind(input, ")" ) != -1 || strfind(input, "{" ) != -1 || strfind(input, "}" ) != -1 || strfind(input, "[" ) != -1 ||
		strfind(input, "]" ) != -1 || strfind(input, "@" ) != -1 || strfind(input, "&" ) != -1 || strfind(input, "|" ) != -1 ||
		strfind(input, "°" ) != -1 || strfind(input, "^" ) != -1 || strfind(input, "*" ) != -1 || strfind(input, "#" ) != -1 ||
		strfind(input, "~" ) != -1 || strfind(input, "<" ) != -1 || strfind(input, ">" ) != -1 || strfind(input, "І" ) != -1 ||
		strfind(input, "і" ) != -1 || strfind(input, "$" ) != -1 || strfind(input, "`" ) != -1 || strfind(input, "ґ" ) != -1 ||
		strfind(input, "Ђ" ) != -1 || strfind(input, "µ" ) != -1 ) return result=1;
		}
		case 2://Only numbers allowed
		{
		if(strfind(input, "a" , true) != -1 || strfind(input, "b" , true) != -1 || strfind(input, "c" , true) != -1 || strfind(input, "d" , true) != -1 ||
		strfind(input, "e" , true) != -1 || strfind(input, "f" , true) != -1 || strfind(input, "g" , true) != -1 || strfind(input, "h" , true) != -1 ||
		strfind(input, "i" , true) != -1 || strfind(input, "j" , true) != -1 || strfind(input, "k" , true) != -1 || strfind(input, "l" , true) != -1 ||
		strfind(input, "m" , true) != -1 || strfind(input, "n" , true) != -1 || strfind(input, "o" , true) != -1 || strfind(input, "p" , true) != -1 ||
		strfind(input, "q" , true) != -1 || strfind(input, "r" , true) != -1 || strfind(input, "s" , true) != -1 || strfind(input, "t" , true) != -1 ||
		strfind(input, "u" , true) != -1 || strfind(input, "v" , true) != -1 || strfind(input, "w" , true) != -1 || strfind(input, "x" , true) != -1 ||
		strfind(input, "y" , true) != -1 || strfind(input, "z" , true) != -1 || strfind(input, "." ) != -1 || strfind(input, "," ) != -1 ||
		strfind(input, "?" ) != -1 || strfind(input, "!" ) != -1 || strfind(input, "Я" ) != -1 || strfind(input, "'" ) != -1 ||
		strfind(input, "-" ) != -1 || strfind(input, "_" ) != -1 || strfind(input, "/" ) != -1 || strfind(input, "(" ) != -1 ||
		strfind(input, ")" ) != -1 || strfind(input, "{" ) != -1 || strfind(input, "}" ) != -1 || strfind(input, "[" ) != -1 ||
		strfind(input, "]" ) != -1 || strfind(input, "@" ) != -1 || strfind(input, "&" ) != -1 || strfind(input, "|" ) != -1 ||
		strfind(input, "°" ) != -1 || strfind(input, "^" ) != -1 || strfind(input, "*" ) != -1 || strfind(input, "#" ) != -1 ||
		strfind(input, "~" ) != -1 || strfind(input, "<" ) != -1 || strfind(input, ">" ) != -1 || strfind(input, "І" ) != -1 ||
		strfind(input, "і" ) != -1 || strfind(input, "$" ) != -1 || strfind(input, "`" ) != -1 || strfind(input, "ґ" ) != -1 ||
		strfind(input, "Ђ" ) != -1 || strfind(input, "µ" ) != -1 || strfind(input, "д" ) != -1 || strfind(input, "ь" ) != -1 ||
		strfind(input, "ц" ) != -1 || strfind(input, ";" ) != -1 || strfind(input, ":" ) != -1 ) return result=1;
		}
	}
	return result;
}
example on how it works:

if you want only numbers and letters in a string, you choose option 1 in checkstring:

PHP код:
if(CheckString(inputtext,1) == 1) return ShowPlayerDialog(playerid,HOUSE_NAME,DIALOG_STYLE_INPUT,"EC House","ERROR: 405\nPlease insert ONLY Numbers and Letters.","Change","Back"); 
if you want only numbers in a string, you set it to 2:

PHP код:
if(CheckString(inputtext,2) == 1) return ShowPlayerDialog(playerid,HOUSE_INVENTORY_C4_ADD,DIALOG_STYLE_INPUT,"EC House","ERROR: 400\nPlease insert ONLY Numbers!","Done","Cancel"); 
Reply
#3

Sweet bro thanks alot.
Reply
#4

There's a much simplier/faster way.

pawn Код:
stock IsNumeric(const string[])
{
    for (new i = 0, j = strlen(string); i < j; i++)
    {
        if (string[i] > '9' || string[i] < '0') return 0;
    }
    return 1;
}
Example of usage:
pawn Код:
if (IsNumeric(inputtext))
{
    // inputtext contains only numbers, do something here..
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)