Call the following address syntax verification function with your email as its param. It returns TRUE for well-formed (RFC822-compliant) email address syntax:
function isWellFormedMailtoScheme email
#- function isWellFormedMailtoScheme(email)
# return TRUE if email is a legal email URI, else return FALSE
# We are not actually *validating* the email address, only its syntax.
# Per address specification rules of RFC822: Standard for ARPA Internet Text Messages
# http://www.w3.org/Protocols/rfc822/Overview.html
# Basic syntax requires: one or more characters before the @ sign,
split email by "@"
if extents(email) <> "1,2" then return false # only 1 @-sign is permitted
put email[2] into hostanddomain
# There are 2 options to check, domain-literal or domain-logical:
# domain-literal option:
# primitive network host address form, must have [###.###.###.###] where 0 < # < 256
if char 1 of hostanddomain = "[" then
if not last char of hostanddomain = "]" then return false
delete char 1 of hostanddomain
delete last char of hostanddomain
set the itemDel to "."
if the num of items of hostanddomain <> 4 then return false
repeat with x = 1 to 4
if not isNumber(item x of hostanddomain) then return false
if item x of hostanddomain > 255 or item x of hostanddomain < 1 then return false
end repeat
return TRUE
end if
# domain-logical option: (the "normal" form)
# this permits an arbitrary number o!
f strings separated by ".", ending in a domain name
set the itemDel to "."
put the num of items of hostanddomain into hostanddomainItems
if hostanddomainItems = 0 then return false
if hostanddomain contains ".." then return false # empty hosts not allowed
repeat with x = length(hostanddomain) down to 1
if not ("0123456789.-abcdefghijklmnopqrstuvwxyz_" contains char x of hostanddomain) \
then return false
end repeat
return TRUE
end isWellFormedMailtoScheme
Sivakatirswami <[EMAIL PROTECTED]> wrote:
Anyone have a set of regExp for use in a matchText function in MC to verify
an email address? I am converting some PERL form cgi's to Metatalk
scripts...all very easy with the exception of this one function.
The PERL script makes two matchText passes:
First: $email !~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/ ||
Second:
$email !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/) {
I was successful in rewriting the first one:
e.g.
put "[EMAIL PROTECTED]" into tEmail
put matchtext (tEmail, "@.*@|\.\.|(@\.)|\.@|^\.")
--returns false as it should...
--it appears it is just checking
--for double entries of periods or @ signs
But the second one is much more difficult... where PERL's regEx
uses a bracket feature to specify a range limit...
put matchtext (tEmail,
"^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9! ]{1,3})(\]?)$")
Here's the full comments from BformMail.pl
# /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/ ||
# the e-mail address contains an invalid syntax. Or, if the #
# syntax does not match the following regular expression pattern #
# it fails basic syntax verification. #
#$email !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/)
# Basic syntax requires: one or more characters before the @ sign, #
# followed by an optional '[', then any number of letters, numbers, #
# dashes or periods (valid domain/IP characters) ending in a period #
# and then 2 or 3 letters (for domain suffixes) or 1 to 3 numbers #
# (for IP addresses). An ending bracket is also allowed as it is #
# valid syntax to have an email address like: user@[255.255.255.0] #
# Return a false value, since the e-mail address did not pass valid #
# syntax. #
return 0;
This is the first time in my whole life attempting to use regEx...
It appears obvious that at least I have to "unspecialize" PERL special
characters by removing the forward slashes for:
@,[ and then the second
regEx looks like this in MetaTalk:
(tEmail, "^.+@([?)[a-zA-Z0-9-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(]?)$")
but the "then 2 or 3 letters (for domain suffixes) or 1 to 3 numbers" which
are using the {2,3} {1,3} don't seem to work in metaTalk...
also, how do you match a space in a metatalk regExp?
Now, I am not "wedded" to using a PERL syntax conversion if someone already
has done this with a whole different strategy... Whatever works.
Hinduism Today
Sivakatirswami
Editor's Assistant/Production Manager
[EMAIL PROTECTED]
www.HinduismToday.com, www.HimalayanAcademy.com,
www.Gurudeva.org, www.hindu.org
Statement on America Under Attack
And
August 2000 Address made at the United Nations
on Stopping the War in the Home:
http://www.saivasiddhanta.o! rg/hawaii/church/policy/attack_on_america_9112001
.html
Archives: http://www.mail-archive.com/[email protected]/
Info: http://www.xworlds.com/metacard/mailinglist.htm
Please send bug reports to <[EMAIL PROTECTED]>, not this list.
Francisco J. Ricardo, Ph.D.
Do You Yahoo!?
NEW from Yahoo! GeoCities - quick and easy web site hosting, just $8.95/month. Yahoo! by Phone.
