检查email唯一性,当然也方便改为这样注册帐号
演示
?
?html文件
XML/HTML Code
- <input?name="username"?id="username"?type="text"?/>??
js文件
JavaScript Code
- <script>??
- $(document).ready(function(){??
- $('#username').keyup(username_check);??
- });??
- ??????
- function?username_check(){????
- var?username?=?$('#username').val();??
- if(username?==?""?||?username.length?<?4){??
- $('#username').css('border',?'3px?#CCC?solid');??
- $('#tick').hide();??
- }else{??
- ??
- jQuery.ajax({??
- ???type:?"POST",??
- ???url:?"check.php",??
- ???data:?'username='+?username,??
- ???cache:?false,??
- ???success:?function(response){??
- if(response?==?1){??
- ????//不可以注册??
- ????$('#username').css('border',?'3px?#C33?solid');???
- ????$('#tick').hide();??
- ????$('#cross').fadeIn();??
- ????}else{??
- ????$('#username').css('border',?'3px?#090?solid');??
- ????$('#cross').hide();??
- ????$('#tick').fadeIn();??
- ?????????}??
- ??
- }??
- });??
- }??
- ??
- ??
- ??
- }??
- ??
- </script>??
check.php
?
PHP Code
- <?php??
- include("conn.php");??
- //??
- $username?=?trim(strtolower($_POST['username']));??
- $username?=?mysql_escape_string($username);??
- ??
- if?(eregi("^[_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3}$",$username))?{???
- ????//email通过检查??
- ????$query?=?"SELECT?email?FROM?username_list?WHERE?email?=?'$username'?LIMIT?1";??
- ????$result?=?mysql_query(?$query?);??
- ????$num?=?mysql_num_rows($result);??
- ??????
- ????echo?$num;??
- }???
- else??
- ??
- {??
- echo?"1";//不能注册??
- ??
- }??
- ?>??
?
原文地址:http://www.freejs.net/article_biaodan_35.html