Email Address Validate 4 Levels JavaScript PHP Verify

Published :
Author :
Adam Khoury
4 different levels of email address validation and verification using JavaScript and PHP. Email address formatting validation can occur on both the client-side and the server-side, but the client-side checks should not be the only validation. Level 1 JavaScript on the client-side of your application <script> function isValidEmail(addr){ var result = false; if(addr.indexOf("@") > -1 && addr.indexOf(".") > -1) { result = true; } return result; } var address = "namepart@domainpart.com"; alert( isValidEmail(address) ); </script> <script> function isValidEmail(addr){ var regex = /^([w-]+(?:.[w-]+)*)@((?:[w-]+.)*w[w-]{0,66}).([a-z]{2,6}(?:.[a-z]{2})?)$/i; var result = false; if ( regex.test(addr) ){ result = true; } return result; } var address = "namepart@domainpart.com"; alert( isValidEmail(address) ); </script> Level 2 http://php.net/manual/en/filter.examples.validation.php <?php $email_a = 'joe@example.com'; $email_b = 'bogus'; if (filter_var($email_a, FILTER_VALIDATE_EMAIL)) { echo "This ($email_a) email address is considered valid."; } if (filter_var($email_b, FILTER_VALIDATE_EMAIL)) { echo "This ($email_b) email address is considered valid."; } ?> Level 3 PHP SMTP Email Validation https://code.google.com/p/php-smtp-email-validation/ Level 4 Inbox Click to Verify Email Address https://www.adamkhoury.com/PHP/video/Sign-Up-Form-and-Email-Activation-PHP-MySQL-JavaScript-Programming-Tutorial