English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
A simple AJAX validation to check if a phone number is registered:
Client Implementation:
<!DOCTYPE html> <html> <head> <meta charset="utf-8">-8"> <style> #btn{width:80px;height:30px;} </style> </head> <body> <form> Please enter the phone number: <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>
Server-side Implementation:
<?php $con = mysqli_connect('localhost', 'username', 'password'); if(! $con ) { die('Connection failed: ' . 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 "Mobile number is registered"; exit; } echo "Mobile number is available"; } mysqli_close($con) ?>
The above article on AJAX+The example of implementing a non-refresh verification of a mobile phone number in PHP that the editor shares with everyone is all the content shared by the editor. I hope it can provide everyone with a reference and hope everyone will support the Yelling Tutorial.
Statement: The content of this article is from the Internet, the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously, and this website does not own the copyright, nor has it been manually edited. It does not assume any relevant legal responsibility. If you find any content suspected of copyright infringement, please send an email to: notice#w3Please report violations by replacing # with @ in the email, and provide relevant evidence. Once verified, this site will immediately delete the infringing content.