jQuery Server Side Validation - Check for Unique Email Address


/ Published in: jQuery
Save to your folder(s)

Just some common code I wanted to put up somewhere that can be used to check for unique email address in database for form registration.


Copy this code and paste it in your HTML
  1. // PHP Code
  2. <?php
  3. //MySQL class: http://mbe.ro/2009/08/30/fast-and-easy-php-mysql-class/
  4. require('../shared/db-class.php');
  5. $email = $_REQUEST["email_address"];
  6. //$email = '[email protected]'; // Just for testing.
  7. $validate = new mysql();
  8. $checkemail = $validate->query("SELECT * FROM users WHERE email_address = '$email'");
  9. if (count($checkemail) == 1){
  10. $valid = "false";
  11. } else {
  12. $valid = "true";
  13. }
  14. echo $valid;
  15. ?>
  16.  
  17. // jQuery
  18. // FORM VALIDATION
  19. $('#form').validate({
  20. rules:{
  21. first_name: "required",
  22. last_name: "required",
  23. email_address: {
  24. required: true,
  25. email: true,
  26. remote: "email-check.php"
  27. }
  28. },messages:{
  29. email_address: {
  30. remote: jQuery.format("{0} is already in use!")
  31. }
  32. }
  33.  
  34. });

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.