Only typing numbers
#1

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..
Reply
#2

I think you could loop through every index and check if it is some other character. havent tested it yet.
Reply
#3

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)