English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
一款简单的无刷新验证手机号是否注册:
客户端实现:
!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="手机号有误"; } 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; } echo "휴대폰 번호 사용 가능"; } mysqli_close($con); ?>
이제 이 ajax+php로 실시간으로 휴대폰 번호를 확인하는 예제는 저가 공유한 모든 내용입니다. 이를 통해 많은 참고를 받으시길 바라며, 많은 지지와 외침 가이드를 기대합니다.
언급: 이 문서의 내용은 인터넷에서 가져왔으며, 저작권자는 모두입니다. 내용은 인터넷 사용자가 자발적으로 기여하고 업로드한 것이며, 이 사이트는 소유권을 가지지 않으며, 인공 편집 처리를 하지 않았으며, 관련 법적 책임도 부담하지 않습니다. 저작권 위반 내용이 있음을 발견하면 이메일을 보내 주시기 바랍니다: notice#oldtoolbag.com(이메일을 보내는 경우, #을 @으로 변경하십시오.)를 통해 신고하시고 관련 증거를 제공하시면, 실제로 확인되면 이 사이트는 즉시 위반된 내용을 삭제할 것입니다.