email validation with regEx

Ken Ray kray at sonsothunder.com
Mon Jul 12 23:32:27 EDT 2004


Here's mine, Sannyasin... it's got a limitation, but it's been good for me:

function isEmail what
  return
matchText(what,"^[A-z0-9_\-\.]+[@][A-z0-9_\-]+([.][A-z0-9_\-]+)+[A-z]$")
  -- supports:
  --   periods in user address (ken.ray at test.com)
  --   multiple subdomains (kenray at test.co.uk)
  --   new domains with more than 2 characters (.info, .museum, etc.)
  -- does not support:
  --   IP addresses
end isEmail


HTH,

Ken Ray
Sons of Thunder Software
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/


> -----Original Message-----
> From: use-revolution-bounces at lists.runrev.com 
> [mailto:use-revolution-bounces at lists.runrev.com] On Behalf Of 
> Sannyasin Sivakatirswami
> Sent: Monday, July 12, 2004 10:24 AM
> To: use-revolution at lists.runrev.com
> Subject: email validation with regEx
> 
> 
> I have a very old (2001) email address validation function 
> from Ricardo 
> (see below) that was created before the full regEx was added to the 
> engine. Now that we have a better regEx engine I suspect we could 
> vastly simply this... does anyone have an upgrade written in 
> xTalk with 
> Revolution regEx they could share? I see in formMail.pl (which I'm 
> abandoning)  a pretty terse function but I don't know if this 
> is a good 
> validation or not nor if I can repurpose the perl regEx to xTalk -- 
> i'll try but I'm a regEx baby hoping for a hand out.... ;-)
> 
> 
> TIA
> 
> Sannyasin Sivakatirswami
> Himalayan Academy Publications
> at Kauai's Hindu Monastery
> katir at hindu.org
> 
> www.HimalayanAcademy.com,
> www.HinduismToday.com
> www.Gurudeva.org
> www.Hindu.org
> 
> ======= from perl:
> 
>      # If the e-mail address contains:                        
>            
>       #
>      if ($email =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/ ||
> 
>          # 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;
>      }
> 
>      else {
> 
>          # Return a true value, e-mail verification passed.   
>            
>       #
>          return 1;
>      }
> 
> ========= old xtalk validator from Ricardo
> 
> 
> 
> 
> 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 of 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
> 
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com 
> http://lists.runrev.com/mailman/listinfo/use-revolution
> 




More information about the use-livecode mailing list