23.06.2010, 18:02
Hi guys, I'm making some commands using dialogs. I would like to know how to do a dialog(DIALOG_STYLE_INPUT) that only you can write words, not numbers.
Sorry for my English.
Sorry for my English.
IsNumeric(const string[])
{
for (new i = 0, j = strlen(string); i < j; i++)
{
if (string[i] > '9' || string[i] < '0')
{
return 0;
}
}
return 1;
}
stock isNumeric(const string[]) {
new length=strlen(string);
if (length==0) return false;
for (new i = 0; i < length; i++) {
if (
(string[i] > '9' || string[i] < '0' && string[i]!='-' && string[i]!='+') // Not a number,'+' or '-'
|| (string[i]=='-' && i!=0) // A '-' but not at first.
|| (string[i]=='+' && i!=0) // A '+' but not at first.
) return false;
}
if (length==1 && (string[0]=='-' || string[0]=='+')) return false;
return true;
}
IsNumeric(const string[])
{
if (!strval(string))
{
for (new i = 0, j = strlen(string); i < j; i++)
{
if (string[i] != '0') return 0;
}
}
return 1;
}
printf("%d\n", IsNumeric("0000")); //returns 1
printf("%d\n", IsNumeric("2341")); //returns 1
printf("%d\n", IsNumeric("+2341")); //returns 1
printf("%d\n", IsNumeric("-2341")); //returns 1
printf("%d\n", IsNumeric("jhb342u")); //returns 0