Jump to content

Validate Email Addresses


LonelyRoad

Recommended Posts

Posted

I am trying to validate an email address passed to a function (as shown in the code below) but no matter what I give the function it always returns no match (and the outputchatbox runs twice for some reason).

function validateEmail(email) 
    local email = tostring(email) 
    if (email:match("[A-Za-z0-9%.%%%+%-]+@[A-Za-z0-9%.%%%+%-]+%.%w%w%w?%w?")) then 
        outputChatBox("Match!") 
        return true 
    else 
        outputChatBox("No Match!") 
        return false 
    end 
end 
addCommandHandler("testing", validateEmail) 

Posted

The first parameter of addCommandHandler is "commandname" for the client side and "playersource" for server side, so use for server side in your function:

validateEmail(_,_,email) 

and for the client:

validateEmail(_,email) 

Posted

For what reason would the 'No Match!' output twice here now?

If the email matches, it returns true and does the outputchatbox once, but if it's no match it does the outputchatbox twice (and presumably returns false twice, too).

Posted

I just tryed it client side. With the command handler ,

"/testing [email protected]" - return one time match in the chatbox.

"/testing asd@yahoo" - return one time no match in the chatbox.

so the function work's well maybe the problem is somewhere else ? you tested it aswell with the CommandHandler ??

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...