一款簡單的無刷新驗證手機號是否注冊:
客戶端實現:
!DOCTYPE html html head meta charset= utf-8 style #btn{width:80px;height:30px;} /style /head body form 請輸入手機號: input type= text id= name name= name input type= button quot;show() id= btn value= 驗證 /form p id= txt /p script var usernamereg = /^1(3|4|5|7|8)/d{9}$/;function show(){ var name=document.getElementById( name ).value;var xmlHttp=new XMLHttpRequest();var url= post.php xmlHttp.onreadystatechange=function stateChanged() if (xmlHttp.readyState==4 || xmlHttp.readyState== complete ){ if(!usernamereg.test(name)){ document.getElementById( txt ).innerHTML= 手機號有誤 }else{ document.getElementById( txt ).innerHTML=xmlHttp.responseText xmlHttp.open( POST ,url,true);xmlHttp.setRequestHeader( Content-type , application/x-www-form-urlencoded xmlHttp.send( name= + name); /script /body /html
服務端實現:
?php$con = mysqli_connect( localhost , username , password if(! $con ) die( 連接失敗: . mysqli_error($con));mysqli_select_db($con, bdm256727651_db $username = select userName FROM Forms where userName = $_POST[name] $result = mysqli_query($con,$username );$rows=mysqli_num_rows($result);if($rows){ echo 手機號已注冊 exit;}else{ echo 手機號可用 mysqli_close($con)?
以上這篇ajax+php實現無刷新驗證手機號的實例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持php 。
您可能感興趣的文章:PHP讀取并輸出XML文件數據的簡單實現方法講解
thinkphp5 加載靜態資源路徑與常量的方法講解
淺析PHP中的閉包和匿名函數解釋
以上就是ajax+php實現無刷新驗證手機號的實例講解的詳細內容,PHP教程
鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。
新聞熱點
疑難解答