Monday, April 21, 2014

The best way to validate email address

Email validation is very important to protect your website from fake registered email addresses. In this post i'm sharing a function which i always use to validate email address.



This function helps to protect some fake email addresses like: example@123-8255.com. This function is first validating the email address using the inbuilt PHP filter_var function. Then it validates the email address using the regular expression and if it's true then it will check for DNS records.
If everything goes good it will return TRUE else will return FALSE.

I still suggest you to build up an email confirmation feature so that you can be sure that the email is 100% valid.
If you have any other trick then do share it in comments.


1 comment:

  1. Very nice!
    I personally would replace replace preg_match -> filter_var($email,FILTER_VALIDATE_EMAIL)

    ReplyDelete

Will be visible after moderation!