Check that a variable is a valid email address


/ Published in: PHP
Save to your folder(s)

Wordpress function


Copy this code and paste it in your HTML
  1. function is_email($user_email) {
  2. $chars = "/^([a-z0-9+_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]{2,6}\$/i";
  3. if(strstr($user_email, '@') && strstr($user_email, '.')) {
  4. if (preg_match($chars, $user_email)) {
  5. return true;
  6. } else {
  7. return false;
  8. }
  9. } else {
  10. return false;
  11. }
  12. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.