怎样在同一个页面实现简单的email地址验证啊解决方案

WBOY
Release: 2016-06-13 10:07:13
Original
932 people have browsed it

怎样在同一个页面实现简单的email地址验证啊
我是个菜鸟,最近在学习php过滤器这一章,想在同一个页面中,输入email地址之后,点击提交,能够验证是否已经输入并且输入是否合法,代码如下,请高手指点。这个代码还实现不了这个功能:



email-test
//

Email-addr:



 
function emailtest($email)

if(filter_has_var(INPUT_GET, "email"))
 {
 
 echo("Input type does not exist");
 }
else
 {
 if (filter_input(INPUT_GET, "email", FILTER_VALIDATE_EMAIL))
  {
  echo "E-Mail is not valid";
  }
 else
  {
  echo "E-Mail is valid";
  }
 }
 }
?>




------解决方案--------------------
。。。我的话很有深意? filter_input()如果验证没通过,才会返回false 
if (filter_input(INPUT_GET, "email", FILTER_VALIDATE_EMAIL))
{
echo "E-Mail is not valid";
}
这句如果变量合法,返回的却是not valid
探讨

引用:

只是你把逻辑弄反了而已


恩恩?请指教,我感觉越来越没逻辑了,经常把自己搞晕。

------解决方案--------------------
function validateEmail($email){
return preg_replace("/^[a-zA-Z0-9]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/", $email);
}

if(!validateEmail($_POST['email'])){
echo "Invalid E-mail: Type a valid e-mail please .";
}
希望可以帮到你
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template