Home arrow PHP arrow Page 2 - Advanced PHP Form Input Validation to Check User Inputs

Validating Email Addresses - PHP

PHP form input validation is what separates amateur and professional PHP developers. A professional PHP developer validates data for both security and correctness of the data entered. Keep reading to learn how to validate user input to your forms.

  1. Advanced PHP Form Input Validation to Check User Inputs
  2. Validating Email Addresses
  3. Validating Domains for Email Addresses
  4. Validating Alphanumeric, Numeric and Alphabetic Input
By: Codex-M
Rating: starstarstarstarstar / 15
June 01, 2009

print this article



Let's start by defining the email address. It contains two sections: the local part and the domain name. For example, in the email address Testuser1@xyz.com, Testuser1 is the local part of the email address while xyz.com is the domain name. Below are the specifications necessary for checking email address validity.

For the local part of the email address, a form should only permit:

  • Uppercase and lowercase English letters (a-z, A-Z)
  • The digits 0 through 9
  • The characters  ! # $ % & ' * + - / = ? ^ _ ` { | } ~
  • The character . provided that it is not the first nor last character; nor may it appear two or more times consecutively.

(Source: RFC Specification: http://en.wikipedia.org/wiki/E-mail_address )

The domain name half of the email address should be a valid domain. Validating an email address is very challenging, especially if you have a version of PHP below 5, because it requires a long Reg Ex syntax using either the ereg or pregmatch function. Luckily, with the release of PHP 5, you can easily validate email addresses using the filter_var / FILTER_VALIDATE_EMAIL function.

This will automatically check versus RFC specifications stated above. The last thing you need to check to find out if the email address is valid is whether the domain name given is valid. There are lots of approaches to this, including checking to see if the domain name has mail exchange records (MX) or A records.

You can find great resources relating to this task at: http://www.devshed.com/c/a/PHP/Email-Address-Verification-with-PHP/

>>> More PHP Articles          >>> More By Codex-M

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: