22.12.2013, 20:34
I have an input dialog and I would like to know how I can make the dialog input restricted to numeric only.
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; }
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(CheckString(inputtext,2) == 1) return ShowPlayerDialog(playerid,HOUSE_INVENTORY_C4_ADD,DIALOG_STYLE_INPUT,"EC House","ERROR: 400\nPlease insert ONLY Numbers!","Done","Cancel");
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;
}
if (IsNumeric(inputtext))
{
// inputtext contains only numbers, do something here..
}