Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Build a Simple PHP Application Wrapping Up The Project Using A Third-Party Library

Johnatan Guzman
PLUS
Johnatan Guzman
Courses Plus Student 2,360 Points

So what exactly is the email validator doing?

It seems like it only checks if there is a @ in the string and then says that the email is valid. So test@adf is valid and test@asdfas.asdfasdf is also valid

But those things are ofcourse invalid, why isnt it checking if there is a (".") in the string that comes after(but not immediately after) the @ sign

Doesnt seem too complicated for seasoned coders.

1 Answer

It is very, very difficult to check if an email address is valid without checking for a response from the domain server etc... but I guess there are a few more checks to put in place when checking to see if a string looks like an email. This is one of the many reasons companies make you 'confirm your account' before using their services. By responding to the 'confirm account email' you instantly validate your address.

This is what the php docs have on email and ip address validation (I guess that phpMailer already uses the filter_var function, I know this is what the Laravel validator uses). This Stack Overflow response adds a few more helpful links for regex comparisons and explanations.