Checking if e-mail is valid
#1

Hi, how is it possible to check if an e-mail is valid? Basically all I want to do is check if "@" and a dot is in the e-mail player entered. I tried checking it with strfind like that:
Код:
if (strfind(inputtext, "@") || strfind(inputtext, "."))
    return SendClientMessage(playerid, COLOR_LIGHTRED, "You have entered an invalid e-mail.");
but it didn't work. It keeps me telling that the e-mal is invalid. I know if it would work players could put more than one dot, etc, but that's still better than nothing. How can I make it work?
Reply
#2

PHP код:
stock IsValidMailAddr(const addr[])
{
    new 
len strlenaddr ),
        
atcount = ( ), IsValid false
    
;
    if( 
len ){
        
IsValid false;
        goto 
IsValidMailAddr__the_end;
    }
    for(new 
ij=leni<ji++){
        if( 
addr[i] == '@' atcount ++;
        if( 
atcount ){
            
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( 
== len )
            if( ( ( 
addr[i] >= 'a' && addr[i] <= 'z' ) || ( addr[i] >= 'A' && addr[i] <= 'Z' ) ) && ( addr[i] != '.' ) )
                
IsValid true;
        if( 
== len && addr[i] == '.' )
            
IsValid false;
    }
    
IsValidMailAddr__the_end:
    return 
IsValid true false;

EDITED, there was a mistake
Reply
#3

Doesn't work. :/
Reply
#4

Best: regex plugin and an expression: [a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+
Works, not so accurate: sscanf(string, "{p<@>s[128]s[50]]}")
Reply
#5

Uh, I don't want any additional plugins, does the sscanf one work? How to use it?
Reply
#6

https://sampforum.blast.hk/showthread.php?tid=547789 may be of some interest, especially Vince's post.
Reply
#7

Quote:
Originally Posted by Ralfie
Посмотреть сообщение
Best: regex plugin and an expression: [a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+
The best way to check the e-mail is like Ralfie answer.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)