Function "IsValidMailAddr" is doing weird
#1

Hi,

I've just made an "IsValidMailAddr" function, but it isn't working how I want it to work.
It's only working one time... ?
Here's the function

pawn Код:
stock IsValidMailAddr(addr[])
{
    new l = 0,
        atcount, bool:IsValid = false
    ;
   
    l = strlen(addr);
   
    loop:l(i){
        if(addr[i] == '@') atcount++;
       
        if( ( (addr[i] >= 'a' && addr[i] <= 'z') || (addr[i] >= 'A' && addr[i] <= 'Z') || (addr[i] == '-') || (addr[i] == '.') ) && atcount == 1 )
            IsValid = true;
        else{
            IsValid = false;
            break;
        }

        if(i == l-1){
            if(!((addr[i] >= 'a' && addr[i] <= 'z') || (addr[i] >= 'A' && addr[i] <= 'Z'))){
                IsValid = false;
                break;
            }
        }
    }
    return IsValid ? true : false;
}
And the test in OnGameModeInit:
pawn Код:
if(IsValidMailAddr("kwarde@rpdsamp.nl")) print("MAIL OK"); else print("MAIL NOT OK"); //MAIL
if(IsValidMailAddr("kwarde@@rpdsamp.nl")) print("MAIL 2 OK"); else print("MAIL 2 NOT OK"); //MAIL 2
if(IsValidMailAddr("kwarde@rpdsamp.nl.")) print("MAIL 3 OK"); else print("MAIL 3 NOT OK"); //MAIL 3
if(IsValidMailAddr("kwarde@rpdsamp.nl")) print("MAIL 4 OK"); else print("MAIL 4 NOT OK"); //MAIL 4
if(IsValidMailAddr("k,warde@rpdsamp.nl")) print("MAIL 5 OK"); else print("MAIL 5 NOT OK"); //MAIL 5
As you can see, "Mail 4" is the same as "Mail". But this is the output in the console:
Код:
MAIL OK
MAIL 2 NOT OK
MAIL 3 NOT OK
MAIL 4 NOT OK
MAIL 5 NOT OK
It says from mail 4 that it isn't OK, while MAIL is OK.

Thanks if you can help me.

- Kevin
Reply


Messages In This Thread
Function "IsValidMailAddr" is doing weird - by Kwarde - 10.02.2011, 18:29
Re: Function "IsValidMailAddr" is doing weird - by Krx17 - 10.02.2011, 20:46
Re: Function "IsValidMailAddr" is doing weird - by Kwarde - 11.02.2011, 04:36
Re: Function "IsValidMailAddr" is doing weird - by Krx17 - 11.02.2011, 04:39
Re: Function "IsValidMailAddr" is doing weird - by Kwarde - 11.02.2011, 05:01
Re: Function "IsValidMailAddr" is doing weird - by Kwarde - 11.02.2011, 05:11

Forum Jump:


Users browsing this thread: 2 Guest(s)