我试图验证我的用户名为电子邮件地址,但PHP不让我这样做!这里有什么问题?php中的电子邮件验证
//This checks if all the fields are filled or not
if (!empty($_POST['username']) ||
!empty($_POST['password']) ||
!empty($_POST['repassword']) ||
!empty($_POST['user_firstname']) ||
!empty($_POST['user_lastname'])){
header('Location: register.php?msg=You didn\'t complete all of the required fields');
}
if (filter_var($_POST['username'], FILTER_VALIDATE_EMAIL) === false){
$errors[] = 'The email address you entered is not valid';
}
这是我在register.php
<form action="createuser.php" method="post" name="registration_form" id="registration_form">
<label>Email</label>
<input name="username" type="text" id="username" size="50" maxlength="50" /><br />
发送给用户一些带有首次密码的电子邮件而不是验证超过这个数量就足够了吗? – budwiser
我只是想确保用户输入一个电子邮件作为用户名! – thedullmistro
你尝试过的电子邮件是什么,或者没有电子邮件? FILTER_VALIDATE_EMAIL允许本地邮件地址不指定全局域,例如“user @ localhost”是一个有效的电子邮件。 – Sven