Quantcast
Viewing all articles
Browse latest Browse all 3

Validate emails the PHP 5 way

Forget the numerous regex’s, if you’re using PHP5 (i hope 99% of you do…), just use PHP’s native filter_var function:

1
2
3
4
5
6
7
8
9
function is_email_valid($email) {
  return filter_var(filter_var($email, FILTER_SANITIZE_EMAIL), FILTER_VALIDATE_EMAIL);
}

if (is_email_valid('email@example.com')) {
  /* yeah! we've got a valid email address */
} else {
  /* oh noes! invalid email */
}

Viewing all articles
Browse latest Browse all 3

Trending Articles