Check email format using php
posted by web10 on 2009-07-03 17:21:46
Hello,
Is there a function to check the format of an email? I found some regex patterns but have different problems.
Ttanks
Is there a function to check the format of an email? I found some regex patterns but have different problems.
Ttanks

12
Do not use regex, there is a php function to do that.(PHP 5 >= 5.2.0)
function is_email($email){ if(filter_var($email, FILTER_VALIDATE_EMAIL)) return true; else return false; }
0
function checkMail($email){ $correct = 0; if ((strlen($email) >= 6) && (substr_count($email,"@") == 1) && (substr($email,0,1) != "@") && (substr($email,strlen($email)-1,1) != "@")){ if ((!strstr($email,"'")) && (!strstr($email,"\"")) && (!strstr($email,"\\")) && (!strstr($email,"\$")) && (!strstr($email," "))) { if (substr_count($email,".")>= 1){ $term_dom = substr(strrchr ($email, '.'),1); if (strlen($term_dom)>1 && strlen($term_dom)<5 && (!strstr($term_dom,"@")) ){ $antes_dom = substr($email,0,strlen($email) - strlen($term_dom) - 1); $caracter_ult = substr($antes_dom,strlen($antes_dom)-1,1); if ($caracter_ult != "@" && $caracter_ult != "."){ $correct = 1; } } } } } return $correct; }
Answer the question
Top Users
- dail (12)
- livin52 (3)
- camu (3)
- softweb (2)
- Nadine (1)
- Josware (1)
- lfelipecr (1)
- gregoriohc (1)
- Mitu (1)
- ryan714 (1)