Check if string is a number
#1

Hey,

how can I check if the insert data in a string is a number or not?
Reply
#2

Use IsNumeric function:

pawn Code:
IsNumeric(const string[])
{
    for (new i = 0, j = strlen(string); i < j; i++)
    {
        if (string[i] > '9' || string[i] < '0') return 0;
    }
    return 1;
}
Reply
#3

pawn Code:
new input;
        format(input, sizeof(input), "%i", inputtext);
        if(input < 12 || input > 120)
        {
What's wrong on that format?

It says:

PHP Code:
(407) : error 035argument type mismatch (argument 1)
(
407) : error 035argument type mismatch (argument 1)
Pawn compiler 3.2.3664              Copyright (c1997-2006ITB CompuPhase
2 Errors

Reply
#4

Try this:
pawn Code:
if(inputtext < 12 || inputtext > 120)
But you need to change something else too.
This is full code:

pawn Code:
new input[128];//You need to define the length of the input before formating it.
        format(input, sizeof(input), "%i", inputtext);
        if(inputtext < 12 || inputtext > 120)
        {
Reply
#5

Well I do this in the OnDialogResponse Callback.

I get the following error:

pawn Code:
(406) : error 033: array must be indexed (variable "inputtext")
pawn Code:
if(inputtext < 12 || inputtext > 120)
{
//...
Reply
#6

Ahh, sorry didn't know that...

Then try:

pawn Code:
if(strval(inputtext) < 12 || strval(inputtext) > 120)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)