2

I use the Zend_Validate_EmailAddress to validate email addresses for my email program. It validates according to the RFC2822 - http://framework.zend.com/manual/en/zend.validate.set.html

My question is are these valid emails when they pass validation?

test@test.co. test@test.co.za. etc Note the full stop at the end.

I find that the validator passes these email addresses which are obviously wrong. I don't fully understand why this should pass can anyone help me?

Regards

Charles
  • 50,943
  • 13
  • 104
  • 142
Etienne Marais
  • 1,660
  • 1
  • 22
  • 40
  • 2
    Including the root zone is technically correct, but not all mailservers like them. For example Exchange always had issues with this. – mario Mar 24 '11 at 12:22

2 Answers2

4

The email addresses are not "obviously wrong"; a DNS name is allowed to end with a trailing . to indicate that it's absolute rather than relative.

[EDITED to add: The above may be misleading. In an email address, for SMTP at least, hostnames are always interpreted as fully-qualified -- i.e., "absolute". So there's never a need for a trailing . in the hostname part of an email address. However, the trailing . is still valid hostname syntax.]

Gareth McCaughan
  • 19,888
  • 1
  • 41
  • 62
  • Okay I agree with you, the fact stands is that the validator threw them out one day and passed them the next. – Etienne Marais Mar 24 '11 at 12:25
  • I have no idea why it would do that, unless you've turned on the `mx` check (which actually talks to an external server to try to discover whether the host in question will accept email; of course that could change for reasons that are entirely out of your control). – Gareth McCaughan Mar 24 '11 at 12:37
  • What does it mean to have a relative or absolute address? – Etienne Marais Mar 24 '11 at 13:38
  • DNS is hierarchical, like a filesystem directory structure. A trailing `.` is like a leading `/` in a Unix pathname and indicates that the name should be used as is. (The actual term is "fully qualified domain name" or FQDN.) Without that, depending on your DNS setup the name may be interpreted relatively; so if you're on machine `foo.bar.com` then the name `baz` may be interpreted as `baz.bar.com`. (Or, in principle, as `baz.com` -- but no one sets their DNS up that way -- or as `baz` at toplevel -- but there is no such host.) – Gareth McCaughan Mar 24 '11 at 14:21
0

Following is the regular expression that is recommended by rfc2822 :

(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])

This regex is time-consuming therefore I believe that Zend went with a simpler regex which unintentionally ignores the trailing fullstop.

Helpful links:
http://www.regular-expressions.info/email.html
http://regexpal.com/

sv_in
  • 13,929
  • 9
  • 34
  • 55