這個程序實現的是用html' target='_blank'>正則表達式實現登錄驗證的一個Demo
<1>:<?php if(isset($_POST["sub"])){ $text=$_POST["text"]; $patten='^[0-9]*$'; if(!preg_match($patten,$text,$x)){ echo"<script>alert('用戶沒有輸入數字');</script>";}else{ if($x<1){ $y=$x; echo "y=".$y."<br>"; }else if($x<10){ $y=2*$x-1; echo "y=".$y."<br>"; }else{ $y=3*$x-11; echo "y=".$y."<br>"; } }?><html><head></head><body><form method='post'>請輸入信息:<input type="text"name="text"><input type="submit"name="sub"value="提交"></form></body></html><2>:<html><head></head><body><form method='post'>注冊賬號:<input type="text"name="aNum"><br>登錄密碼:<input type="password"name="pwd"><br>重復密碼:<input type="password"name="rPwd"><br>郵箱地址:<input type="text"name="email"><br>手機號碼:<input type="text"name="tel"><br><input type="submit"name="sub"value="注冊"><?php if(isset($_POST["sub"])){ $aNum=$_POST["aNum"]; $pwd=$_POST["pwd"]; $rPwd=$_POST["rPwd"]; $email=$_POST["email"]; $tel=$_POST["tel"]; $patten1="^w+(.[w-]+)*@[w-]+(.[w-]+)+$";//驗證郵箱 $patten2="[0-9]{11}";//11位數字組成,驗證手機號碼 $patten3="[a-zA-Z_-ÿ][a-zA-Z0-9_-ÿ]*"//驗證賬號 if(!preg_match($patten3,$aNum)){ echo"<script>alert('賬號格式不對');</script>"; }else{ if($pwd.length<6){ echo"<script>alert('密碼格式不對');</script>"; }else{ if(!preg_match($patten,$email)){ echo"<script>alert('email格式不正確');</script>"; }else{ if(!preg_match($patten2,$tel)){ echo"<script>alert('手機號碼格式不正確');</script>"; }else{ if(strlen($pwd)!=strlen($rPwd)){ echo"<script>alert('兩次密碼不一致');</script>"; }else{ echo"用戶您好!您的賬號為:".$aNum.",密碼為:".$pwd.",郵箱為:". $email.",手機號碼為:".$tel; } } } }} ?></form></body></html>PHP編程
鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。
新聞熱點
疑難解答