You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 3.1 KiB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # isemail
  2. Node email address validation library
  3. [![Build Status](https://travis-ci.org/hapijs/isemail.svg?branch=master)](https://travis-ci.org/hapijs/isemail)<a href="#footnote-1"><sup>&#91;1&#93;</sup></a>
  4. Lead Maintainer: [Eli Skeggs][skeggse]
  5. This library is a port of the PHP `is_email` function by Dominic Sayers.
  6. Install
  7. =======
  8. ```sh
  9. $ npm install isemail
  10. ```
  11. Test
  12. ====
  13. The tests were pulled from `is_email`'s extensive [test suite][tests] on October 15, 2013. Many thanks to the contributors! Additional tests have been added to increase code coverage and verify edge-cases.
  14. Run any of the following.
  15. ```sh
  16. $ lab
  17. $ npm test
  18. $ make test
  19. ```
  20. _remember to_ `npm install` to get the development dependencies!
  21. API
  22. ===
  23. validate(email, [options])
  24. --------------------------
  25. Determines whether the `email` is valid or not, for various definitions thereof. Optionally accepts an `options` object. Options may include `errorLevel`.
  26. Use `errorLevel` to specify the type of result for `validate()`. Passing a `false` literal will result in a true or false boolean indicating whether the email address is sufficiently defined for use in sending an email. Passing a `true` literal will result in a more granular numeric status, with zero being a perfectly valid email address. Passing a number will return `0` if the numeric status is below the `errorLevel` and the numeric status otherwise.
  27. The `tldBlacklist` option can be either an object lookup table or an array of invalid top-level domains. If the email address has a top-level domain that is in the whitelist, the email will be marked as invalid.
  28. The `tldWhitelist` option can be either an object lookup table or an array of valid top-level domains. If the email address has a top-level domain that is not in the whitelist, the email will be marked as invalid.
  29. The `allowUnicode` option governs whether non-ASCII characters are allowed. Defaults to `true` per RFC 6530.
  30. Only one of `tldBlacklist` and `tldWhitelist` will be consulted for TLD validity.
  31. The `minDomainAtoms` option is an optional positive integer that specifies the minimum number of domain atoms that must be included for the email address to be considered valid. Be careful with the option, as some top-level domains, like `io`, directly support email addresses.
  32. As of `3.1.1`, the `callback` parameter is deprecated, and will be removed in `4.0.0`.
  33. ### Examples
  34. ```js
  35. $ node
  36. > var Isemail = require('isemail');
  37. undefined
  38. > Isemail.validate('test@iana.org');
  39. true
  40. > Isemail.validate('test@iana.123');
  41. true
  42. > Isemail.validate('test@iana.org', {errorLevel: true});
  43. 0
  44. > Isemail.validate('test@iana.123', {errorLevel: true});
  45. 10
  46. > Isemail.validate('test@iana.123', {errorLevel: 17});
  47. 0
  48. > Isemail.validate('test@iana.123', {errorLevel: 10});
  49. 10
  50. > Isemail.validate('test@iana&12');
  51. false
  52. > Isemail.validate('test@iana&12', {errorLevel: true});
  53. 65
  54. > Isemail.validate('test@', {errorLevel: true});
  55. 131
  56. ```
  57. <sup name="footnote-1">&#91;1&#93;</sup>: if this badge indicates the build is passing, then isemail has 100% code coverage.
  58. [skeggse]: https://github.com/skeggse "Eli Skeggs"
  59. [tests]: http://isemail.info/_system/is_email/test/?all‎ "is_email test suite"