Home > Backend Development > PHP Tutorial > php5中的应验合法性的扩展

php5中的应验合法性的扩展

WBOY
Release: 2016-06-13 11:03:10
Original
886 people have browsed it

php5中的验证合法性的扩展
在PHP5.2中,可以通过内置的扩展过滤器去进行合法性的校验,例子如下:

1 验证是否email:
  email = "[email protected]";
if (filter_var($email, FILTER_VALIDATE_EMAIL))
  {
  echo "Valid email address!"; }
  else
{
echo "Invalid email address!";

}


2 验证是否整数
  if (filter_var($age), FILTER_VALIDATE_INT, array('options' => array('min_range' => 13, 'max_range' => 100)))
{
  echo "Valid age!";
}
else
{
echo "Invalid age!";
}


3 跟正则表达式
   if (filter_var($age), FILTER_VALIDATE_INT, array('options' => array('min_range' => 13, 'max_range' => 100)))
  {
  echo "Valid age!";
  }
else
{
  echo "Invalid age!";

}


 

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