email syntax validation needed

Nevin Pratt nevin at smalltalkpro.com
Tue Jul 22 04:19:19 UTC 2003


Derek,

I had a customer with an email address of their name, followed by 
'@sbcglobal.net'.  NetNameResolver wasn't able to resolve the domain 
'sbcglobal.net', so the code I showed you below tagged the email address 
as a bad address when in fact it was good.

Anybody know how to do MX record lookups from within Squeak rather than 
DNS lookups?  Seems on my system, 'sbcglobal.net' resolves to a good MX 
record, but fails as a DNS lookup.

Nevin



Nevin Pratt wrote:

>>
>
> Derek,
>
> What did you finally use in your quest on this topic?  Here is a piece 
> of code I use.  It requires that the email address have a $@ character 
> in it.  It requires that the hostname portion following that character 
> be resolvable via DNS (and it must resolve within 5 seconds).  And it 
> requires that the username portion of it not have a space (I've found 
> putting spaces in the username to be a very common user error).  You 
> can see I can easily expand the list of bad characters in the username 
> portion if I choose to, although I never have:
>
> isValidEmailAddress: emailAddress
>    | username |
>    emailAddress isNil
>        ifTrue: [^ false].
>    (NetNameResolver
>            addressForName: (emailAddress copyAfter: $@)
>            timeout: 5) isNil
>        ifTrue: [^ false].
>    username _ emailAddress copyUpTo: $@.
>    (username includesAnyOf: ' ')
>        ifTrue: [^ false].
>    ^ true
>

-- 
Nevin Pratt
Bountiful Baby
http://www.bountifulbaby.com
(801) 992-3137





More information about the Squeak-dev mailing list