[Zope] Valid email address...

Max M maxm@mxm.dk
Fri, 12 Apr 2002 10:06:22 +0200


Peter Bengtsson wrote:

>Bruce Eckels gave me this. It has been working very fine for me.
>Peter
>
>def ShouldBeNone(result): return result is not None
>def ShouldNotBeNone(result): return result is None
>
>tests = (
>  (re.compile("^[0-9a-zA-Z\.\-\_]+\@[0-9a-zA-Z\.\-]+$"), ShouldNotBeNone, 
>"Fail$  (re.compile("^[^0-9a-zA-Z]|[^0-9a-zA-Z]$"), ShouldBeNone, "Failed b"),
>  (re.compile("([0-9a-zA-Z]{1})\@."), ShouldNotBeNone, "Failed c"),
>  (re.compile(".\@([0-9a-zA-Z]{1})"), ShouldNotBeNone, "Failed d"),
>  (re.compile(".\.\-.|.\-\..|.\.\..|.\-\-."), ShouldBeNone, "Failed e"),
>  (re.compile(".\.\_.|.\-\_.|.\_\..|.\_\-.|.\_\_."), ShouldBeNone, "Failed 
>f"),
>  (re.compile(".\.([a-zA-Z]{2,3})$|.\.([a-zA-Z]{2,4})$"), ShouldNotBeNone, 
>"Fai$)
>
>
>def ValidEmailAddress(address, debug=None):
>    for test in tests:
>        if test[1](test[0].search(address)):
>            if debug: return test[2]
>            return 0
>    return 1
>

I do understand that it is possible to create code that checks a lot 
more than my simple snippet.

But my problem with code like that is that it gives an impression of a 
precission that really isn't there. You can check all you want ind still 
not be shure it's a valid mail adress. But someone might assume that a 
mailadress that is checked with such precision is always valid, and so 
they might skip the nessacary tests to check if mail bounces elsewhere 
in code.

It's like making an estimated time like 35.2313 hours in a budget. Then 
when you are an hour late the customer complains. Where if you had said 
1 week +- a day to make the precision more clear it would be allright.

regards Max M, Software Psychologist ;-)