일부 전자 메일 주소의 유효성을 검사하고 싶습니다. 입력이 텍스트 영역에 사용자에 의해 주어진 상기 주소 같이, 콤마로 구분된다 PHP : 배열의 전자 메일 주소 유효성 검사
[email protected], [email protected], 등등
이 스크립트는 I$emailadressen = explode(',', $_POST['uitnodigen']);
$aantal = count($emailadressen);
$i = 1;
foreach($emailadressen as $emails)
{
if(check_email_address($emails) == false) {
$Melding['omschrijving'] = '<div class="error">Error in address number '.$i.'</div>';
$i++;
}
}
그리고 이것은 내가 사용하는 기능입니다 : : 배열은 하나의 EMAILADDRESS이 문제와 EV 없다 포함 된 경우
function check_email_address($email) {
// First, we check that there's one @ symbol, and that the lengths are right
if (!preg_match("/^[^@]{1,64}@[^@]{1,255}$/", $email)) {
// Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
return false;
}
// Split it into sections to make life easier
$email_array = explode("@", $email);
$local_array = explode(".", $email_array[0]);
for ($i = 0; $i < sizeof($local_array); $i++) {
if (!preg_match("/^(([A-Za-z0-9!#$%&'*+\/=?^_`{|}~-][A-Za-z0-9!#$%&'*+\/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$/", $local_array[$i])) {
return false;
}
}
if (!preg_match("/^\[?[0-9\.]+\]?$/", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name
$domain_array = explode(".", $email_array[1]);
if (sizeof($domain_array) < 2) {
return false; // Not enough parts to domain
}
for ($i = 0; $i < sizeof($domain_array); $i++) {
if (!preg_match("/^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$/", $domain_array[$i])) {
return false;
}
}
}
return true;
}
주소를 확인하는 데 사용 erything 잘 작동합니다.
하지만 적어도 2 개의 emailaddress를 가질 때마다 매번 오류 오류가 발생합니다. (이메일 주소가 유효한 경우에도)
내가 뭘 잘못 했니?
[php 이메일 필터] (http://php.net/manual/en/filter.filters.validate.php)를 살펴보십시오. – Fluffeh
http://stackoverflow.com/questions/13719821/email-validation-using-regular-expression-in-php –