User Email Input Format Check?

Is there an email address sanitization library for Corona that anyone’s aware of, something to help with input error checking for accepting input from native.newTextField? [import]uid: 1560 topic_id: 24585 reply_id: 324585[/import]

This is really, really basic but it might help - I just put it together as a little sample as I’m not aware of a library off hand.

[lua]display.setStatusBar (display.HiddenStatusBar)

local input

local function listener (event)
if event.phase == “submitted” then
print (input.text)
atSymbol = string.find(input.text, “@”, 1)
dotSymbol = string.find(input.text, “.com”, 1)
if atSymbol ~= nil and dotSymbol ~= nil and dotSymbol > atSymbol+1 then
print “@ and .com exist”
else
print “Oops, try again”
end
end
end

input = native.newTextField(10, 10, 200, 20)
input:addEventListener(“userInput”, listener)[/lua]

All that does is check that “@” and “.com” (obviously you’d want to expand on that) are present and that there is text between them, with .com appearing after @.

If you do find a library please let me know!

Peach :slight_smile: [import]uid: 52491 topic_id: 24585 reply_id: 99521[/import]

Thanks, Peach. [import]uid: 1560 topic_id: 24585 reply_id: 99548[/import]

email="apebooth@domain.es"  
if (email:match("[A-Za-z0-9%.%%%+%-]+@[A-Za-z0-9%.%%%+%-]+%.%w%w%w?%w?")) then  
 print(email .. " is a valid email address")  
else  
 print(email .. " is not a valid email address")  
end  
  

[import]uid: 113117 topic_id: 24585 reply_id: 112572[/import]

Please note that correct/proper email validation is really hard to get right because email addresses (RFC 822) accept a lot of weird and complicated things.

Roberto Ierusalimschy (creator of Lua) briefly mentions it here:
http://lua-users.org/lists/lua-l/2009-10/msg00817.html

I’ve been pushing to get LPeg into Corona. We still don’t have an ETA on it though.

On my personal note as a user standpoint, do not disallow perfectly valid email addresses. This drives me to aggravation. I often use the + symbol and . and very long email addresses which are the top 3 things that I get rejected for. (But there are others besides those 3.) If you are going to validate emails and can’t use a proven correct algorithm, I recommend you allow for bad email addresses to pass instead of failing valid email addresses.

[import]uid: 7563 topic_id: 24585 reply_id: 112595[/import]