11.02.2011, 05:11
EDIT: Sorry, I forgot the EDIT button 'cuz I'm in a hurry. I gotta go now
It's working now
The test:
The output:
- Kevin
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;
}
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
Код:
MAIL OK MAIL 2 NOT OK MAIL 3 NOT OK MAIL 4 OK MAIL 5 NOT OK