您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息
三六零分类信息网 > 新乡分类信息网,免费分类信息发布

实例分析ajax和php实现无刷新验证手机号

2025/3/14 13:35:12发布7次查看
本文主要为大家分享一篇ajax+php实现无刷新验证手机号的实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧,希望能帮助到大家。
一款简单的无刷新验证手机号是否注册:
客户端实现:
<!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" onclick="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) ?>
相关推荐:
asp.net ajax实现无刷新验证码
php+jquery ajax邮箱地址无刷新验证实例_php教程
jquery实现无刷新验证码的简单实例_jquery
以上就是实例分析ajax和php实现无刷新验证手机号的详细内容。
新乡分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录