/server/lib/validation/email.js

https://github.com/edwindotcom/browserid-bigtent · JavaScript · 17 lines · 7 code · 2 blank · 8 comment · 5 complexity · f91e6f3339f6412bcd5a1f7f8520c38a MD5 · raw file

  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. module.exports = function (address) {
  5. // Copied from mozilla/browserid which got it from...
  6. // http://blog.gerv.net/2011/05/html5_email_address_regexp/
  7. var parts = address.split("@");
  8. return /^[\w.!#$%&'*+\-/=?\^`{|}~]+@[a-z\d-]+(\.[a-z\d-]+)+$/i.test(address)
  9. // total address allwed to be 254 bytes long
  10. && address.length <= 254
  11. // local side only allowed to be 64 bytes long
  12. && parts[0] && parts[0].length <= 64
  13. // domain side allowed to be up to 253 bytes long
  14. && parts[1] && parts[1].length <= 253;
  15. };