php5中的应验合法性的扩展

WBOY
Release: 2016-06-13 13:02:08
Original
1107 people have browsed it

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!";

}


 

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!