Code Monkey home page Code Monkey logo

email-rfc2822-validator's Introduction

APACHE v2 License Latest Release Build Status Codacy

email-rfc2822-validator

The world's only more-or-less-2822-compliant Java-based email address extractor / verifier

email-rfc2822-validator is available in Maven Central:

<dependency>
    <groupId>com.github.bbottema</groupId>
    <artifactId>emailaddress-rfc2822</artifactId>
    <version>1.1.0</version>
</dependency>

And just to show you that this stuff is hard, here's JavaMail's official parser's javadoc on the subject (line 669):

    /*
     * RFC822 Address parser.
     *
     * XXX - This is complex enough that it ought to be a real parser,
     *       not this ad-hoc mess, and because of that, this is not perfect.
     *
     * XXX - Deal with encoded Headers too.
     */
    @SuppressWarnings("fallthrough")
    private static InternetAddress[] parse(String s, boolean strict,
				    boolean parseHdr) throws AddressException {

Usage

There are two classes available, EmailaddressValidator and EmailAddressParser. The second is used to extract data from (complex / mangled) email strings.

For both of these, you use the EmailAddressCriteria enumeration to control RFC strictness.

Here's an example for validating an email address:

boolean isValid = EmailAddressValidator.isValid(emailaddress);
boolean isValid = EmailAddressValidator.isValid(emailaddress, EmailAddressCriteria.DEFAULT);
boolean isValid = EmailAddressValidator.isValid(emailaddress, EmailAddressCriteria.RFC_COMPLIANT);
boolean isValid = EmailAddressValidator.isValid(emailaddress, EnumSet.of(ALLOW_DOT_IN_A_TEXT, ALLOW_SQUARE_BRACKETS_IN_A_TEXT));

Latest Progress

v1.1.0

  • #7: Clarified validation modes (default vs strictly rfc compliant)

NOTE: EmailAddressValidator.isValid() now validates using EmailAddressCriteria.DEFAULT rather than EmailAddressCriteria.RFC_COMPLIANT. Use EmailAddressValidator.isValidStrict() for RFC compliant validation.

v1.0.1

Initial release

email-rfc2822-validator's People

Contributors

bbottema avatar chconnor avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.