Php-幾種有效的驗證
來自站長百科
- 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("請輸入小寫、大寫字母!"); }