智慧水务管理系统 - 精河县供水工程综合管理平台

email-utils.js 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { isAlphaNumericOrMarkChar, isValidEmailLocalPartSpecialChar } from '../char-utils';
  2. import { isKnownTld } from './uri-utils';
  3. /**
  4. * A regular expression to match a 'mailto:' prefix on an email address.
  5. */
  6. export var mailtoSchemePrefixRe = /^mailto:/i;
  7. /**
  8. * Determines if the given character may start the "local part" of an email
  9. * address. The local part is the part to the left of the '@' sign.
  10. *
  11. * Technically according to the email spec, any of the characters in the
  12. * {@link emailLocalPartCharRegex} can start an email address (including any of
  13. * the special characters), but this is so rare in the wild and the
  14. * implementation is much simpler by only starting an email address with a word
  15. * character. This is especially important when matching the '{' character which
  16. * generally starts a brace that isn't part of the email address.
  17. */
  18. export var isEmailLocalPartStartChar = isAlphaNumericOrMarkChar; // alias for clarity
  19. /**
  20. * Determines if the given character can be part of the "local part" of an email
  21. * address. The local part is the part to the left of the '@' sign.
  22. *
  23. * Checking for an email address's start char is handled with {@link #isEmailLocalPartStartChar}
  24. */
  25. export function isEmailLocalPartChar(charCode) {
  26. return isEmailLocalPartStartChar(charCode) || isValidEmailLocalPartSpecialChar(charCode);
  27. }
  28. /**
  29. * Determines if the given email address is valid. We consider it valid if it
  30. * has a valid TLD in its host.
  31. *
  32. * @param emailAddress email address
  33. * @return true is email have valid TLD, false otherwise
  34. */
  35. export function isValidEmail(emailAddress) {
  36. var emailAddressTld = emailAddress.split('.').pop(); // as long as we have a valid string (as opposed to null or undefined), we will always get at least one element in the .split('.') array
  37. return isKnownTld(emailAddressTld);
  38. }
  39. //# sourceMappingURL=email-utils.js.map