I came into that :
Code: Select all
print(string.match(email,'[(%w+)%p*]+@[%w+%p*]+%.%a+$'))
Any wise advises ?
Code: Select all
print(string.match(email,'[(%w+)%p*]+@[%w+%p*]+%.%a+$'))
Code: Select all
email="alex@it-rfc.de"
if (email:match("[A-Za-z0-9%.%%%+%-]+@[A-Za-z0-9%.%%%+%-]+%.%w%w%w?%w?")) then
print(email .. " is a valid email address")
end
Code: Select all
print(string.match(email,'^[%w+%.%-_]+@[%w+%.%-_]+%.%a%a+$'))
Thanks Kadoba...Well, that's a bit complex to me...I get the general idea, but what does the "%.%%%+%-" part in the set "[A-Za-z0-9%.%%%+%-]+" stands for ?Kadoba wrote:Found this in string recipes on the lua wiki.
Code: Select all
email="alex@it-rfc.de" if (email:match("[A-Za-z0-9%.%%%+%-]+@[A-Za-z0-9%.%%%+%-]+%.%w%w%w?%w?")) then print(email .. " is a valid email address") end
Code: Select all
%. -- dot
%% -- % symbol
%+ -- + simbol
%- -- - symbol
Good point. It gets closer to what I proposed first.flashkot wrote:Code: Select all
print(string.match(email,'^[%w+%.%-_]+@[%w+%.%-_]+%.%a%a+$'))
Unfortunately, patterns in Lua are not so powerful like RegEx.Roland_Yonaba wrote:Good point. It gets closer to what I proposed first.flashkot wrote:Code: Select all
print(string.match(email,'^[%w+%.%-_]+@[%w+%.%-_]+%.%a%a+$'))
Whatever, this regex will validate strings containing for instance two or more punctuation characters following themselves...
Something like Darth..Vader@DeathStar.mil
Code: Select all
print(string.match(email,'^[%w+%-_]*%.?[%w+%-_]*%.?[%w+%-_]*%.?[%w+%-_]*%.?[%w+%-_]*%.?[%w+%-_]*%.?[%w+%-_]+@[%w+%-_]*%.?[%w+%-_]*%.?[%w+%-_]*%.?[%w+%-_]*%.?[%w+%-_]*%.?[%w+%-_]+%.%a%a+$'))
For the domain-part :
- Up to 64 characters long
- Uppercase and lowercase English letters (a–z, A–Z) (ASCII: 65–90, 97–122)
- Digits 0 to 9 (ASCII: 48–57)
- Characters !#$%&'*+-/=?^_`{|}~ (ASCII: 33, 35–39, 42, 43, 45, 47, 61, 63, 94–96, 123–126)
- Character . (dot, period, full stop) (ASCII: 46) provided that it is not the first or last character, and provided also that it does not appear two or more times consecutively (e.g. John..Doe@example.com is not allowed.).
The domain name part of an email address has to conform to strict guidelines: it must match the requirements for a hostname, consisting of letters, digits, hyphens and dots.
Code: Select all
function _.isEmail(str)
local _,nAt = str:gsub('@','@') -- Counts the number of '@' symbol
if nAt > 1 or nAt == 0 or str:len() > 254 or str:find('%s') then return false end
local localPart = _.strLeft(str,'@') -- Returns the substring before '@' symbol
local domainPart = _.strRight(str,'@') -- Returns the substring after '@' symbol
if not localPart or not domainPart then return false end
if not localPart:match("[%w!#%$%%&'%*%+%-/=%?^_`{|}~]+") or (localPart:len() > 64) then return false end
if localPart:match('^%.+') or localPart:match('%.+$') or localPart:find('%.%.+') then return false end
if not domainPart:match('[%w%-_]+%.%a%a+$') or domainPart:len() > 253 then return false end
local fDomain = _.strLeftBack(domainPart,'%.') -- Returns the substring in the domain-part before the last (dot) character
if fDomain:match('^[_%-%.]+') or fDomain:match('[_%-%.]+$') or fDomain:find('%.%.+') then return false end
return true
end
Users browsing this forum: No registered users and 5 guests