未雨绸缪的名言:Php

来源:百度文库 编辑:偶看新闻 时间:2024/04/29 01:52:41
  • E-mail验证
$email = htmlspecialchars($_POST['email']);if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email)){    die("E-mail地址不合法");}
  • URL地址
$url = htmlspecialchars($_POST['website']);if (!preg_match("/^(https?:\/\/+[\w\-]+\.[\w\-]+)/i",$url)){    die("URL 地址不合法");} 
  • 只能够数字0-9
if (preg_match("/\D/",$age)){    die("年龄只能够用数字");}
  • 只能够小写字母和大写字母
if (preg_match("/[^a-zA-Z]/",$text)){    die("请输入小写、大写字母!");}