一款简单的无刷新验证手机号是否注册:
客户端实现:
!DOCTYPE html html hearteta charset=' utf-8 ' style # BTN { width :80 px;高度:30 px}/样式/标题格式请输入手机号:输入类型='text' id='name' name='name '输入类型=' button ' onclick=' show()' id=' BTN ' value='验证/formp id=' txt '/pscriptvar usernamereg=/^1(3|4|5|7|8)d{9}$/;函数show(){ var name=document。getelementbyid(' name ').价值;var xmlHttp=new XMLHttpRequest();var url=' post.phpxmlhttp。onreadystatechange=函数状态已更改(){ if(xmlhttp。readystate==4 | | xmlhttp。readystate==' complete '){ if(!usernamereg。测试(名称)){文档。getelementbyid(' txt ').innerHTML='手机号有误;} else { document。getelementbyid(' txt ').innerHTML=xmlhttp。responsetext } } } xmlhttp。open(' POST ',url,true);xmlhttp。setrequestheader('内容类型','应用程序/x-www-form-URL编码');xmlhttp。发送(' name=' name ');}/脚本/正文/html服务端实现:
?PHP $ con=MySQL _ connect(' localhost ',' username ',' password ');if(!$con ){ die('连接失败: ' .MySQL _ error($ con));} MySQL _ select _ db($ con,' bdm 256727651 _ db ');$username='从表单中选择用户名,其中userName=' $ _ POST[name]';$ result=MySQL _ query($ con,$ username);$ rows=MySQL _ num _ rows($ result);if($ row){ echo '手机号已注册;退出;}else{echo '手机号可用;} MySQL _ close($ con)?以上这篇聊天室实现无刷新验证手机号的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持我们。