Skip to content
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.

Support granular diagnosis exclusion #187

Merged
merged 2 commits into from
Oct 18, 2018
Merged

Conversation

skeggse
Copy link
Owner

@skeggse skeggse commented Oct 7, 2018

This adds a new excludeDiagnoses option (documentation pending) to Isemail.validate which specifies a set of diagnostic codes to exclude from validation. For example, consider the following diagnoses:

rfc5321TLD: 9,
rfc5321TLDNumeric: 10,
rfc5321QuotedString: 11,
rfc5321AddressLiteral: 12,

If you want to accept 11, and 12, but prohibit 10, you'd previously need to run isemail twice with two different errorLevels. That workaround doesn't scale well beyond a single gap, however. With the new excludeDiagnoses option, we can be more specific about what to allow through:

const options = {
    errorLevel: Isemail.diagnoses.rfc5321TLDNumeric,
    excludeDiagnoses: [
        Isemail.diagnoses.rfc5321QuotedString,
        Isemail.diagnoses.rfc5321AddressLiteral
    ]
};

Isemail.validate('joe@[127.0.0.1]', options) // => true
Isemail.validate('[email protected]', options) // => false
Isemail.validate('"joe"@hapijs.com', options) // => true

Fixes #180. Is also an imperfect solution to #162.

@skeggse skeggse merged commit 7b685e0 into master Oct 18, 2018
@skeggse skeggse deleted the granular-diagnosis-exclusion branch October 18, 2018 16:23
@skeggse
Copy link
Owner Author

skeggse commented Oct 18, 2018

Released in 3.2.0.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant