An array of C#, PHP, and HTML programming articles, tutorials, and resources

Posts Tagged ‘ validation ’

Verify Email Address in PHP

by Victor | September 24, 2008 in PHP | 5 Comments

Nearly every interactive web application requires at some point a user to register. So generally, there exists a registration page where site visitors input basic information like username, password, and email address. Aside from the username and password, what is the easiest way for a PHP web developer to verify an email address is at the very least properly formatted (whether this is an active account is a whole separate matter)?

The approach that come to mind first is to do a simple email string check:

  1. Make sure the email string contains at most one ‘at’ symbol (@)
  2. Make sure the email string contains at least one ‘period’ symbol (.) after the ‘at’ symbol (@)
  3. Make sure the email string contains at least one character before the at symbol (@)
  4. Make sure the email string contains at least one character between the ‘at’ symbol (@) and the ‘period’ symbol (.)
  5. Make sure the email string contains at least one character after the ‘period’ symbol (.)

For starters, this is no easy task. Note that the five suggested steps above is not even complete. Many might suggest a complex regex verification process. I have personally attempted to write a regex and even PHP based checker. During this process, I found a great PHP Email Address Validation function available under BSD License which, among others things, allows commercial use. [More]