Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Validating Email Addresses In PHP (The Right Way) (bobpattersonjr.com)
2 points by nleach on Sept 14, 2012 | hide | past | favorite | 4 comments


Please edit the link as Validating Email Addresses The Wrong Way

The right way is

  filter_var('bob@example.com', FILTER_VALIDATE_EMAIL);
Same for validating the domain. And also : http://news.ycombinator.com/item?id=4486108


FILTER_VALIDATE_EMAIL probably is a smarter way to go, but I think context matters a lot. If this is for a consumer web service user@hostname isn't going to be 'valid' for the service.


If this is for a consumer web service, user@existing.dns for a non-existing mail box will be 'valid' according to this link, but still completely useless.

Please see the link I posted.

1/ Using PHP PCRE for email validation is considered harmful

2/ Using filter_var for email validation for a web service is useless

3/ Sending a confirmation link by email is the way to go


I think you're missing the point. The idea is to provide incremental knowledge about the validity of the address, both to the user and to the service. user@existing.dns will validate but user@exsiting.dns won't. There is real value in providing that feedback immediately, rather than forcing the user to realize after waiting for an email that will never arrive that they made a trivial mistake.

To be clear, I agree with you 100% that there is no substitute for sending a confirmation email and requiring the user to click-through if you're looking for full confirmation of mailbox validity. My point is that there are simple steps to be taken along that path which complement the confirmation email.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: