当前位置: 代码迷 >> Ajax >> php jquery check username ajax检察帐号唯一性
  详细解决方案

php jquery check username ajax检察帐号唯一性

热度:2196   发布时间:2014-03-01 00:37:28.0
php jquery check username ajax检查帐号唯一性

检查email唯一性,当然也方便改为这样注册帐号

演示

?

?html文件

XML/HTML Code
  1. <input?name="username"?id="username"?type="text"?/>??

js文件

JavaScript Code
  1. <script>??
  2. $(document).ready(function(){??
  3. $('#username').keyup(username_check);??
  4. });??
  5. ??????
  6. function?username_check(){????
  7. var?username?=?$('#username').val();??
  8. if(username?==?""?||?username.length?<?4){??
  9. $('#username').css('border',?'3px?#CCC?solid');??
  10. $('#tick').hide();??
  11. }else{??
  12. ??
  13. jQuery.ajax({??
  14. ???type:?"POST",??
  15. ???url:?"check.php",??
  16. ???data:?'username='+?username,??
  17. ???cache:?false,??
  18. ???success:?function(response){??
  19. if(response?==?1){??
  20. ????//不可以注册??
  21. ????$('#username').css('border',?'3px?#C33?solid');???
  22. ????$('#tick').hide();??
  23. ????$('#cross').fadeIn();??
  24. ????}else{??
  25. ????$('#username').css('border',?'3px?#090?solid');??
  26. ????$('#cross').hide();??
  27. ????$('#tick').fadeIn();??
  28. ?????????}??
  29. ??
  30. }??
  31. });??
  32. }??
  33. ??
  34. ??
  35. ??
  36. }??
  37. ??
  38. </script>??

check.php

?

PHP Code
  1. <?php??
  2. include("conn.php");??
  3. //??
  4. $username?=?trim(strtolower($_POST['username']));??
  5. $username?=?mysql_escape_string($username);??
  6. ??
  7. if?(eregi("^[_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3}$",$username))?{???
  8. ????//email通过检查??
  9. ????$query?=?"SELECT?email?FROM?username_list?WHERE?email?=?'$username'?LIMIT?1";??
  10. ????$result?=?mysql_query(?$query?);??
  11. ????$num?=?mysql_num_rows($result);??
  12. ??????
  13. ????echo?$num;??
  14. }???
  15. else??
  16. ??
  17. {??
  18. echo?"1";//不能注册??
  19. ??
  20. }??
  21. ?>??

?


原文地址:http://www.freejs.net/article_biaodan_35.html

  相关解决方案