Function "IsValidMailAddr" is doing weird
#6

EDIT: Sorry, I forgot the EDIT button 'cuz I'm in a hurry. I gotta go now

It's working now
pawn Код:
stock IsValidMailAddr(const addr[])
{
    new len = strlen( addr ),
        atcount = ( 0 ), IsValid = false
    ;
    if( len < 5 ){
        IsValid = false;
        goto IsValidMailAddr__the_end;
    }
    loop:len(i){
        if( addr[i] == '@' ) atcount ++;
        if( atcount > 1 ){
            IsValid = false;
            break;
        }
       
        if( ( addr[i] >= 'a' && addr[i] <= 'z' ) || ( addr[i] >= 'A' && addr[i] <= 'Z' ) || ( addr[i] == '.' ) || ( addr[i] == '_' ) || ( addr[i] == '-' ) )
            IsValid = true;
        else{
            if( ( addr[i] != '@' ) ){
                IsValid = false;
                break;
            }
        }

        if( i + 1 == len )
            if( ( ( addr[i] >= 'a' && addr[i] <= 'z' ) || ( addr[i] >= 'A' && addr[i] <= 'Z' ) ) && ( addr[i] != '.' ) )
                IsValid = true;
        if( i + 1 == len && addr[i] == '.' ) //unneeded? :P
            IsValid = false;
    }
    IsValidMailAddr__the_end:
    return IsValid ? true : false;
}
The test:

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
The output:

Код:
MAIL OK
MAIL 2 NOT OK
MAIL 3 NOT OK
MAIL 4 OK
MAIL 5 NOT OK
- 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: 1 Guest(s)