Php-几种有效的验证:修订间差异

来自站长百科
跳转至: 导航、​ 搜索
(新页面: <span style="text-align:center; border:1px solid #000; float:right; padding:6px;"><strong>导航:</strong> 上一页 | {{template:开发语言导航}}</span> *'''E-mail...)
 
无编辑摘要
 
第1行: 第1行:
<span style="text-align:center; border:1px solid #000; float:right; padding:6px;"><strong>导航:</strong> [[PHP#PHP教程|上一页]] | {{template:开发语言导航}}</span>
<div style="text-align:center; border:1px solid #000; float:right; padding:6px;"><strong>导航:</strong> [[PHP#PHP教程|上一页]] | {{template:开发语言导航}}</div>


*'''E-mail验证'''
 
*E-mail验证
<pre>
<pre>
$email = htmlspecialchars($_POST['email']);
$email = htmlspecialchars($_POST['email']);
第19行: 第20行:
if (!preg_match("/^(https?:\/\/+[\w\-]+\.[\w\-]+)/i",$url))
if (!preg_match("/^(https?:\/\/+[\w\-]+\.[\w\-]+)/i",$url))
{
{
     die("URL address not valid");
     die("URL 地址不合法");
}
}
   
   

2010年6月23日 (三) 17:02的最新版本

导航: 上一页 | ASP | PHP | JSP | HTML | CSS | XHTML | aJAX | Ruby | JAVA | XML | Python | ColdFusion


  • E-mail验证
$email = htmlspecialchars($_POST['email']);

if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email))

{

    die("E-mail地址不合法");

}
$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("请输入小写、大写字母!");

}

参考资料[ ]

资料1