help for validemail

Title

validemail -- Email address validation using Regex, DNS/MX lookups, and disposable domain detection

Syntax

validemail varname [, options]

generate(newvar) New variable for validation status codes (Default: validated_status)

dns(newvar) New variable for extracted domains (Default: validated_domain)

ip(newvar) New variable for server IP addresses (Default: validated_ip)

disposable(newvar) New variable indicating disposable email domains (Default: validated_disposable)

mx Check for MX (Mail Exchanger) records instead of simple A records

lowercase Convert emails to lowercase before validation

mergereport Display a tabulation of the validation results

regex(string) Override the default RFC-compliant-ish regex pattern

Description

validemail provides a multi-stage validation for email address variables. It performs:

1. Regex Check: Verifies the format matches standard email patterns.

2. Disposable Check: Compares domains against a list of known disposable email providers (e.g., mailinator.com).

3. DNS/MX Lookup: Uses nslookup to verify the domain exists and can receive mail (if mx is specified).

Status Codes

The generate() variable contains the following codes:

0: Invalid format (Regex failed)

1: Valid format, but DNS/MX lookup failed (domain might not exist)

2: Valid format and DNS/MX lookup passed

3: Valid format and DNS/MX passed, but the domain is a known disposable provider

Options

generate(newvar) specifies the name of the new variable to hold the validation status.

dns(newvar) specifies the name of the new variable to hold the domain extracted from the email.

mx instructs the command to specifically look for MX (Mail Exchanger) records. This is a more accurate way to verify if a domain is configured to receive emails.

lowercase converts all email addresses to lowercase before validation. This is recommended as email domains are case-insensitive.

mergereport displays a summary table of the validation results using the generated status codes.

regex(string) allows you to provide a custom regular expression for the initial format check.

Examples

1. Basic validation of an email variable:

. validemail email_address, mergereport

2. Strict validation with MX check and lowercase conversion:

. validemail email, mx lowercase generate(email_status) mergereport

3. Using a custom regex:

. validemail email, regex("^[a-z]+@[a-z]+\.com$")

Author

Eric A. Booth

eric.a.booth@gmail.com

https://github.com/ericbooth/ValidEmail-stata

Also See

Online: ustrregexm, nslookup