/index.html

https://gitlab.com/Blueprint-Marketing/validator-demo · HTML · 108 lines · 87 code · 21 blank · 0 comment · 0 complexity · d4262c846290247b2da6be63b6347f20 MD5 · raw file

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Advanced jQuery Email Address Validator by Mailgun</title>
  5. <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
  6. <meta content="utf-8" http-equiv="encoding">
  7. <style>
  8. .success{color:#2ECC40;}
  9. .error{color:#FF4136;}
  10. .warning{color:#FF851B;}
  11. </style>
  12. </head>
  13. <body>
  14. <h1>Advanced jQuery Email Address Validator by Mailgun</h1>
  15. <form>
  16. <div>
  17. <label for="email">Email address</label><br>
  18. <input type="email" name="email" id="email">
  19. <div id="status"></div>
  20. </div>
  21. <div>
  22. <button type="submit" id="validate_submit">Validate</button>
  23. </div>
  24. </form>
  25. <p>Try some invalid addresses:
  26. <ul>
  27. <li><strong>john@gmail.com</strong>: Does not meet Gmail minimum local-part length of 6 characters.</li>
  28. <li><strong>john.smith@gmaill.com</strong>: Invalid, because gmaill.com does not have valid MX records.</li>
  29. <li><strong>john@microsoft.io</strong>: Invalid because while microsoft.io does not have any MX records, it does have fallback A records, but alas no Mail Exchanger responds.</li>
  30. </ul>
  31. </p>
  32. <p>Try some valid addresses:
  33. <ul>
  34. <li><strong>john.smith@gmail.com</strong>: Meets Gmail 6 character minimum and all other requirements.</li>
  35. <li><strong>"hello world"@domain.com</strong>: Meets pure syntax checks.</li>
  36. </ul>
  37. </p>
  38. <p>Remember to <a href="http://www.mailgun.com">sign up for Mailgun</a> to receive your public API key.</p>
  39. <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
  40. <script src="mailgun_validator.js"></script>
  41. <script>
  42. // document ready
  43. $(function() {
  44. // capture all enter and do nothing
  45. $('#email').keypress(function(e) {
  46. if(e.which == 13) {
  47. $('#email').trigger('focusout');
  48. return false;
  49. }
  50. });
  51. // capture clicks on validate and do nothing
  52. $("#validate_submit").click(function() {
  53. return false;
  54. });
  55. // attach jquery plugin to validate address
  56. $('#email').mailgun_validator({
  57. api_key: 'MAILGUN_PUBKEY', // replace this with your Mailgun public API key
  58. in_progress: validation_in_progress,
  59. success: validation_success,
  60. error: validation_error,
  61. });
  62. });
  63. // while the lookup is performing
  64. function validation_in_progress() {
  65. $('#status').html("<img src='loading.gif' height='16'/>");
  66. }
  67. // if email successfull validated
  68. function validation_success(data) {
  69. $('#status').html(get_suggestion_str(data['is_valid'], data['did_you_mean']));
  70. }
  71. // if email is invalid
  72. function validation_error(error_message) {
  73. $('#status').html(error_message);
  74. }
  75. // suggest a valid email
  76. function get_suggestion_str(is_valid, alternate) {
  77. if (alternate) {
  78. return '<span class="warning">Did you mean <em>' + alternate + '</em>?</span>';
  79. } else if (is_valid) {
  80. return '<span class="success">Address is valid.</span>';
  81. } else {
  82. return '<span class="error">Address is invalid.</span>';
  83. }
  84. }
  85. </script>
  86. </body>
  87. </html>