codice:
'controllo validità e-mail
function emailaddresstest(emailaddr)
dim ava, charcode, domain, localpart, subdomain, subdomains, tld
'check for valid syntax in an email address
emailaddresstest=true
'parse out the local part and the domain
ava=instrrev(emailaddr,"@")
if ava <= 1 then
emailaddresstest=false
exit function
end if
localpart=left(emailaddr,ava-1)
domain=mid(emailaddr,ava+1)
if len(localpart) < 1 or len(domain) < 3 then
emailaddresstest=false
exit function
end if
'check for invalid characters in the local part
for ava=1 to len(localpart)
charcode=asc(mid(localpart,ava,1))
if charcode < 32 or charcode >= 127 then
emailaddresstest=false
exit function
end if
next
'check for invalid characters in the domain
domain=lcase(domain)
for ava=1 to len(domain)
charcode=asc(mid(domain,ava,1))
if not ((charcode >= 97 and charcode <= 122) or (charcode >= 48 and charcode <= 57) or charcode=45 or charcode=46) then
emailaddresstest=false
exit function
end if
next
'check each subdomain
subdomains=split(domain,".")
for each subdomain in subdomains
if len(subdomain) < 1 then
emailaddresstest=false
exit function
end if
next
'last subdomain should be a TDL
tld=subdomains(ubound(subdomains))
if not isarray(validtlds) then
call setvalidtlds()
end if
for ava=lbound(validtlds) to ubound(validtlds)
if tld=validtlds(ava) then
exit function
end if
next
emailaddresstest=false
end function
sub setvalidtlds()
'load the global list of valid TLDs
validtlds=array("ac", "ad", "ae", "aero", "af", "ag", "ai", "al", _
"am", "an", "ao", "aq", "ar", "as", "at", "au", "aw", "az", "ba", _
"bb", "bd", "be", "bf", "bg", "bh", "bi", "biz", "bj", "bm", "bn", _
"bo", "br", "bs", "bt", "bv", "bw", "by", "bz", "ca", "cc", "cd", _
"cf", "cg", "ch", "ci", "ck", "cl", "cm", "cn", "co", "com", _
"coop", "cr", "cu", "cv", "cx", "cy", "cz", "de", "dj", "dk", _
"dm", "do", "dz", "ec", "edu", "ee", "eg", "eh", "er", "es", "et", _
"fi", "fj", "fk", "fm", "fo", "fr", "ga", "gd", "ge", "gf", "gg", _
"gh", "gi", "gl", "gm", "gn", "gov", "gp", "gq", "gr", "gs", "gt", _
"gu", "gw", "gy", "hk", "hm", "hn", "hr", "ht", "hu", "id", "ie", _
"il", "im", "in", "info", "int", "io", "iq", "ir", "is", "it", _
"je", "jm", "jo", "jp", "ke", "kg", "kh", "ki", "km", "kn", "kp", _
"kr", "kw", "ky", "kz", "la", "lb", "lc", "li", "lk", "lr", "ls", _
"lt", "lu", "lv", "ly", "ma", "mc", "md", "mg", "mh", "mil", "mk", _
"ml", "mm", "mn", "mo", "mp", "mq", "mr", "ms", "mt", "mu", _
"museum", "mv", "mw ", "mx", "my", "mz", "na", "name", "nc", "ne", _
"net", "nf", "ng", "ni", "nl", "no", "np", "nr", "nu", "nz", "om", _
"org", "pa", "pe", "pf", "pg", "ph", "pk", "pl", "pm", "pn", "pr", _
"pro", "ps", "pt", "pw", "py", "qa", "re", "ro", "ru", "rw", "sa", _
"sb", "sc", "sd", "se", "sg", "sh", "si", "sj", "sk", "sl", "sm", _
"sn", "so", "sr", "st", "sv", "sy", "sz", "tc", "td", "tf", "tg", _
"th", "tj", "tk", "tm", "tn", "to", "tp", "tr", "tt", "tv", "tw", _
"tz", "ua", "ug", "uk", "um", "us", "uy", "uz", "va", "vc", "ve", _
"vg", "vi", "vn", "vu", "wf", "ws", "ye", "yt", "yu", "za", "zm", _
"zw")
end sub