PageRenderTime 147ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/nlw/share/javascript/Socialtext/Email.js

https://github.com/audreyt/socialtext-open
JavaScript | 26 lines | 16 code | 4 blank | 6 comment | 0 complexity | 1459eaa05c5b904f6b542dc51cd1ee6f MD5 | raw file
  1. // Regular expression for validating email addresses. Not perfect,
  2. // but close enough to eliminate the majority of invalid addresses,
  3. // which erring on the side of caution. Adapted from here:
  4. //
  5. // http://fightingforalostcause.net/misc/2006/compare-email-regex.php
  6. //
  7. Socialtext.prototype.check_email = (function($) {
  8. var EMAIL_ADDRESS = "([a-zA-Z0-9_'+*$%\\^&!\\.\\-])+"
  9. + "@"
  10. + "(([a-zA-Z0-9\\-])+\\.)+"
  11. + "([a-zA-Z0-9:]{2,4})+";
  12. var EMAIL_ADDRESS_REGEX = new RegExp(
  13. "^" + EMAIL_ADDRESS + "$", "i"
  14. );
  15. var EMAIL_WITH_NAME_REGEX = new RegExp(
  16. "^[^<]+<" + EMAIL_ADDRESS + ">$", "i"
  17. )
  18. return function(email_address) {
  19. return EMAIL_ADDRESS_REGEX.test(email_address) ||
  20. EMAIL_WITH_NAME_REGEX.test(email_address);
  21. };
  22. })(jQuery);