Only typing numbers - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Only typing numbers (
/showthread.php?tid=395560)
Only typing numbers -
Elysian` - 26.11.2012
Hello,
I want to know how I'd make someone only type numbers, etc for their age and they can't type anything else other than numbers..
Re: Only typing numbers -
Nordic - 26.11.2012
I think you could loop through every index and check if it is some other character. havent tested it yet.
Re: Only typing numbers -
Bicentric - 26.11.2012
You can use the function 'IsNumeric'. It's not a default part of the SA-MP library but it's easily implemented using a macro or added function.
pawn Код:
stock IsNumeric(const string[]) //@Credits to CaHbKo.
{
for (new i = 0, j = strlen(string); i < j; i++)
{
if (string[i] > '9' || string[i] < '0') return 0;
}
return 1;
}
Using that, you can check if they only typed in numbers, if there are any non numeric characters in the string, it will return 0, and when it does, you can send them an error and prompt them to enter their age again.