我試圖驗證我的用戶名爲電子郵件地址,但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