Solemnly declare: This article is written by the author based on my personal understanding. errors are inevitable. Please be prepared!
You can reprint, modify, and indicate the source when reprinting!
The valid email address format is as follows:
1. The first character must contain letters, and other characters can only contain 26 uppercase/lowercase letters, 0 ~ 9 and _-. @ symbol
2. It must contain one and only one symbol "@".
3. @ must contain at least one of the three symbols "."
4. the first character cannot be "@" or "." (the first step has been checked)
5. "@." Or ". @" cannot appear .@
6. The end cannot be the character "@" or "."
Code implementation:
1 function isRightEmail(str) 2 if string.len(str or "") < 6 then return false end 3 local b,e = string.find(str or "", '@') 4 local bstr = "" 5 local estr = "" 6 if b then 7 bstr = string.sub(str, 1, b-1) 8 estr = string.sub(str, e+1, -1) 9 else10 return false11 end12 13 -- check the string before '@'14 local p1,p2 = string.find(bstr, "[%w_]+")15 if (p1 ~= 1) or (p2 ~= string.len(bstr)) then return false end16 17 -- check the string after '@'18 if string.find(estr, "^[%.]+") then return false end19 if string.find(estr, "%.[%.]+") then return false end20 if string.find(estr, "@") then return false end21 if string.find(estr, "[%.]+$") then return false end22 23 _,count = string.gsub(estr, "%.", "")24 if (count < 1 ) or (count > 3) then25 return false26 end27 28 return true29 end