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

php5中的应验合法性的扩展

WBOY
WBOYOriginal
2016-06-13 13:02:081109browse

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

1 验证是否email:
  email = "jason@example.com";
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!";

}


 

Statement:
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