【发布时间】:2012-10-04 09:13:19
【问题描述】:
我正在尝试将我的用户名验证为电子邮件地址,但是 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 />
【问题讨论】:
-
向用户发送一些带有首次密码的电子邮件并且不进行更多验证就足够了吗?
-
我只是想确保用户输入了电子邮件作为用户名!
-
您尝试的电子邮件是什么,还是非电子邮件? FILTER_VALIDATE_EMAIL 允许不指定全局域的本地邮件地址,例如"user@localhost" 是一个有效的电子邮件。
-
如果我输入任何字符串,它会接受它作为电子邮件地址。我希望它只接受电子邮件地址的
标签: php html sql email-validation