1.3.2 • Published 7 months ago

email-validator-dns-provider-rules v1.3.2

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

Email validator with DNS check and provider's rules

Examples, that other validators pass:

invalid emailreason
som_e-one@gmail.comGmail don't allows "_" and "-" symbols
someone@8avymt4v93mvt3t03.com"8avymt4v93mvt3t03.com" isn't real domain and dont have DNS MX records
s!o#m$e%o^n&e@realdomain.com99.99% public email providers allow only "a-z","0-9",".","_","-","+" before "@" part
someone@hotnail.compossibility of adding your blocklist of domains and MX domains

Works in Browser and Node. TypeScript and JavaScript.

Usage

Please install NPM package (works in browser also)

npm install email-validator-dns-provider-rules --save

Validation:

import { isValidEmail } from "email-validator-dns-provider-rules";

if (!await isValidEmail('someone@gmail.com')) {
    alert('Your email is invalid');
}

Showing details:

import { isValidEmail, getLastInvalidText } from "email-validator-dns-provider-rules";

if (!await isValidEmail('someone@gmail.com')) {
    alert('Please correct your email: ' + getLastInvalidText());
}

Your version of invalid reasons text

You can use getLastInvalidReasonId() and make dictionary with your version of text:

const CUSTOM_INVALID_TEXT = {
    [INVALID_REASON_AMOUNT_OF_AT]: 'no @ symbol or too many of them',
    [INVALID_REASON_USERNAME_GENERAL_RULES]:
        'invalid username before @ by general email rules',
    [INVALID_REASON_DOMAIN_GENERAL_RULES]:
        'invalid domain after @ by general domain rules',
    [INVALID_REASON_NO_DNS_MX_RECORDS]: 'domain after @ has no DNS MX records',
    [INVALID_REASON_DOMAIN_IN_BLOCKLIST]: 'email domain is in blocklist',
    [INVALID_REASON_USERNAME_VENDOR_RULES]:
        'invalid username before @ by domain vendor rules',
};

Passing your blocklist domains

const yourBlocklistDomains = ['somedomain.com', '...'];
isValidEmail('someone@gmail.com', yourBlocklistDomains);

Passing your DOH provider

You can choose other DNS over HTTPS provider or even create your own

isValidEmail('someone@gmail.com', null, 'https://your-provider-site/dns-query');

Testing

npm test

Generating d.ts

npm i -g typescript
tsc
1.3.2

7 months ago

1.3.1

7 months ago

1.3.0

7 months ago

1.2.0

12 months ago

1.2.1

12 months ago

1.1.0

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago