後世に…
$email1 = filter_var('aaa@email.com', FILTER_VALIDATE_EMAIL);
$email2 = filter_var('aaa@email.com', FILTER_VALIDATE_EMAIL);
$unmatched1 = filter_var('aaa@emil.com', FILTER_VALIDATE_EMAIL);
$unmatched2 = filter_var('aab@email.com', FILTER_VALIDATE_EMAIL);
$invalid1 = filter_var('aaa.com', FILTER_VALIDATE_EMAIL);
$invalid2 = filter_var('email.com', FILTER_VALIDATE_EMAIL);
$empty = filter_var('', FILTER_VALIDATE_EMAIL);
var_dump(!$email1 || $email1 !== $email2);
var_dump(!$email1 || $email1 !== $unmatched2);
var_dump(!$unmatched1 || $unmatched1 !== $email2);
var_dump(!$email1 || $email1 !== $invalid2);
var_dump(!$invalid1 || $invalid1 !== $email2);
var_dump(!$email1 || $email1 !== $empty);
var_dump(!$empty || $empty !== $email2);
与えます:
bool(false) // Desired in validation...
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
https://ignite.io/code/511f8bf8ec221e7f21000000
したがって、置き換えvar_dump
てif
単純化するとe-mail2
(検証する必要はありません):
$email = filter_var($_POST['e-mail'], FILTER_VALIDATE_EMAIL);
if (!$email || $email !== $_POST['e-mail2']) {
// error stuff, including separate check on empty.
}