$email='fst_-gh@163.com';//$pattern='^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$';//$pattern='^[_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3}$';$pattern='^[_.0-9a-z-]+@([0-9a-z]+.)+[a-z]{2,3}$'; if (eregi($pattern,$email)) { echo "OK";}else{ echo"err";}
preg_match 邮箱验证方法 (以下三种方法都可以)
$pattern="/([A-Za-z0-9\_]+)\@([\w\-]+)\.([a-z]{2,3})/";$pattern2="/(^[A-Za-z0-9\_]+)\@([0-9a-z][0-9a-z-]+)\.([a-z]{2,3}$)/";$pattern3="/([\w\-]+\@[\w\-]+\.[a-z]{2,3}$)/";if (preg_match($pattern3,$email)) { echo "emailok"; }
echo"难证用户名
";$username='sfdsf432_';$pattern='/[\w]{6,20}/'; if(preg_match($pattern,$username)){ echo"username OK";} echo"验证浮点型
";$number='33.25';$pattern='/^[1-9]([0-9]*)\.(\d+)/';if(preg_match($pattern,$number)){ echo"number ok";}echo"验证url
";$url='http://www.163.com/df/?=dsf';$pattern='/^(http|https):\/\/([\w]+\.)?([\w][\w\-]*)+\.(com|org|net|dk|at|us|tv|info|uk|cn|cc)/';if(preg_match($pattern,$url)){ echo"url ok";}echo"验证 ip
";$ip='192.168.1.1';$pattern='/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/';if(preg_match($pattern,$ip)){ echo"ip ok";}echo"验证 html
";$html="sdf";$pattern="/^<(.*)>.*<\/(.*)>|<(.*) \/>/";if(preg_match($pattern,$html)){ echo"html ok";}