How to check
#1

How to check to see if a player enters numbers on DIALOG_STYLE_INPUT,
And how to make sure that he enters 4 numbers, And if he dosent, Returns msg
Reply
#2

I know that but how do i check if he entered numbers, And 4 numbers,

It can be anything, But it has to be numbers and it has to be 4 digits
Reply
#3

pawn Код:
if(strlen(inputtext) == 4 && IsNumeric(inputtext))
Reply
#4

Wouldnt that check if the player entered 4?

Let me try explain better:

Im making a bit on my server where you need to enter the year you were born,
So i need to know if they entered numbers ( Got that, Thanks for the code )
And that its 4 digits

So

****

Example: 1990
Reply
#5

That is what i said. Here is my function to check, if birth date is valid. I hope, it will help you a lot.

pawn Код:
stock bool:IsValidDate(day, month, year)
{
new actual_day, actual_month, actual_year;
getdate(actual_year, actual_month, actual_day);
if(day < 1 || month < 1 || year < 1 || day > 31 || month > 12 || year > actual_year) return false;
if(year == actual_year)
{
if(month > actual_month) return false;
if(month == actual_month && day > actual_day) return false;
}
switch(month)
{
case 2: if((year % 4 && day > 28) || day > 29) return false;
case 4: if(day == 31) return false;
case 6: if(day == 31) return false;
case 9: if(day == 31) return false;
case 11: if(day == 31) return false;
}
return true;
}
Reply
#6

pawn Код:
if(!IsNumeric(inputtext) || strlen(inputtext) < 0 || strlen(inputtext) > 4 || strval(inputtext) < 1960 || strval(inputtext) > 2010) return printf("No inputtext 4 char and numeric and no value 1960 - 2010");
    else printf("perfect %d", strval(inputtext));
Simplifield:
pawn Код:
if(!IsNumeric(inputtext) || strval(inputtext) < 1960 || strval(inputtext) > 2010) return print("inputtext no value 1960 - 2010");
    else printf("perfect %d", strval(inputtext));
pawn Код:
stock IsNumeric(string[])
{
    for (new i = 0, j = strlen(string); i < j; i++)
    {
        if (string[i] > '9' || string[i] < '0') return false;
    }
    return true;
}
Final:
pawn Код:
if(strval(inputtext) < 1960 || strval(inputtext) > 2010) return print("inputtext no value 1960 - 2010");
    else printf("perfect %d", strval(inputtext));
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)