SA-MP Forums Archive
How to disable alphabets in inputtext? - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: How to disable alphabets in inputtext? (/showthread.php?tid=155294)



How to disable alphabets in inputtext? - ||123|| - 17.06.2010

I only want numbers to be written in inputtext. If someone writes alphabets, it sends him a error message?


Re: How to disable alphabets in inputtext? - MadeMan - 17.06.2010

pawn Код:
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;
}
pawn Код:
if(!isNumeric(inputtext))
{
  // Error Message
}