PageRenderTime 601ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/nlw/share/legacy/s3/javascript/email.js

https://github.com/audreyt/socialtext-open
JavaScript | 29 lines | 16 code | 7 blank | 6 comment | 0 complexity | 0b4a4872ddd719247a8a34f3cdc9629c 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. Class('Email.Page', 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. this.check_address = function(email_address) {
  19. return EMAIL_ADDRESS_REGEX.test(email_address) ||
  20. EMAIL_WITH_NAME_REGEX.test(email_address);
  21. };
  22. });