Skip to main content

Validation Functions

AnoFox Tabular provides 26 validation functions across 4 domains: 3 email functions (regex in under 1ms, DNS lookup in ~100ms, SMTP verification in ~500ms), 4 address functions powered by libpostal for international address normalization, 9 phone functions built on Google's libphonenumber library with carrier detection and mobile identification, and 10 VAT functions covering format validation, EU VIES verification (~200ms), company name lookup, and standard rate retrieval for 29 European countries. All offline-capable functions execute in under 1ms per record.

Email, address, phone, and VAT validation APIs.

Quick Reference

FunctionDescriptionSQL Signature
anofox_tab_email_validateValidate email(email, mode) -> BOOLEAN
anofox_tab_phone_validateValidate phone(number, country) -> BOOLEAN
anofox_tab_vat_is_validValidate VAT format(vat_id) -> BOOLEAN
anofox_tab_vat_verify_euVerify EU VIES(vat_id) -> BOOLEAN
anofox_tab_address_validateValidate address(address) -> BOOLEAN
anofox_tab_postal_code_validateValidate postal(code, country) -> BOOLEAN

Email Functions (3)

anofox_tab_email_validate

Validate email using one of three modes.

Parameters

ParameterTypeRequiredDefaultDescription
emailVARCHARYes-Email address to validate
modeVARCHARYes-'regex' (<1ms), 'dns' (~100ms), 'smtp' (~500ms)

Returns: TRUE if valid, FALSE if invalid, NULL if error

Example

SELECT
email,
anofox_tab_email_validate(email, 'regex') as syntax_valid,
anofox_tab_email_validate(email, 'dns') as domain_valid,
anofox_tab_email_validate(email, 'smtp') as mailbox_valid
FROM customers;

anofox_tab_email_extract_domain

Extract domain from email address.

SELECT anofox_tab_email_extract_domain('john@example.com');
-- Output: example.com

anofox_tab_email_normalize

Normalize email (lowercase, trim whitespace).

SELECT anofox_tab_email_normalize('  John@Example.COM  ');
-- Output: john@example.com

Address Functions (4)

anofox_tab_address_validate

Validate street address format.

SELECT anofox_tab_address_validate('123 Main St, New York, NY 10001');
-- Output: true

anofox_tab_postal_code_validate

Validate postal code for country.

Parameters

ParameterTypeRequiredDefaultDescription
codeVARCHARYes-Postal code
countryVARCHARYes-2-letter country code

Example

SELECT
anofox_tab_postal_code_validate('90210', 'US'), -- true
anofox_tab_postal_code_validate('SW1A 1AA', 'GB'), -- true
anofox_tab_postal_code_validate('75001', 'FR'); -- true

anofox_tab_address_get_state

Extract state or province.

SELECT anofox_tab_address_get_state('123 Main St, New York, NY 10001');
-- Output: NY

anofox_tab_address_get_city

Extract city.

SELECT anofox_tab_address_get_city('123 Main St, New York, NY 10001');
-- Output: New York

Phone Functions (9)

anofox_tab_phone_format

Format phone number to standard format.

Parameters

ParameterTypeRequiredDefaultDescription
numberVARCHARYes-Phone number (any format)
countryVARCHARYes-2-letter country code

Example

SELECT
anofox_tab_phone_format('+1-555-0123', 'US'), -- '+1 555 0123'
anofox_tab_phone_format('0203 946 0958', 'GB'); -- '+44 20 3946 0958'

anofox_tab_phone_validate

Validate phone number for country.

SELECT
anofox_tab_phone_validate('+1-555-0123', 'US'), -- true
anofox_tab_phone_validate('123', 'US'); -- false

anofox_tab_phone_get_country_code

Extract country code.

SELECT anofox_tab_phone_get_country_code('+44 20 3946 0958');
-- Output: GB

anofox_tab_phone_is_mobile

Check if mobile number.

SELECT anofox_tab_phone_is_mobile('+1 555 0123', 'US');  -- true

anofox_tab_phone_get_carrier

Get carrier/operator name.

SELECT anofox_tab_phone_get_carrier('+1 555 0123', 'US');
-- Output: 'Verizon' (example)

anofox_tab_phone_normalize

Normalize to E.164 format.

SELECT anofox_tab_phone_normalize('555-0123');
-- Output: +15550123

VAT Functions (10)

anofox_tab_vat_is_valid

Validate VAT ID format.

SELECT
anofox_tab_vat_is_valid('DE123456789'), -- true
anofox_tab_vat_is_valid('INVALID'); -- false

anofox_tab_vat_get_country

Extract country code from VAT ID.

SELECT anofox_tab_vat_get_country('DE123456789');
-- Output: DE

anofox_tab_vat_verify_eu

Verify VAT ID in EU VIES system (~200ms).

SELECT anofox_tab_vat_verify_eu('DE123456789');
-- Output: true (if registered)

anofox_tab_vat_get_company_name

Get company name from VIES registration (~200ms).

SELECT anofox_tab_vat_get_company_name('DE123456789');
-- Output: 'Example GmbH'

anofox_tab_vat_format

Format VAT ID to country standard.

SELECT anofox_tab_vat_format('de123456789');
-- Output: 'DE123456789'

anofox_tab_vat_is_eu_member

Check if country is EU member.

SELECT
anofox_tab_vat_is_eu_member('DE'), -- true
anofox_tab_vat_is_eu_member('US'), -- false
anofox_tab_vat_is_eu_member('GB'); -- false (post-Brexit)

anofox_tab_vat_get_standard_rate

Get standard VAT rate for country.

SELECT
anofox_tab_vat_get_standard_rate('DE'), -- 0.19 (19%)
anofox_tab_vat_get_standard_rate('FR'); -- 0.20 (20%)

Performance Characteristics

FunctionSpeedNetworkCacheable
Email regex<1msNoYes
Email DNS~100msYesYes
Email SMTP~500msYesNo
Phone~5-50msNoNo
VAT format<1msNoYes
VAT VIES~200msYesYes

The performance profile reveals a clear strategy for production pipelines: use offline validation (regex, format checks) for bulk processing at sub-millisecond speeds, and reserve network-dependent validation (DNS, SMTP, VIES) for targeted verification of flagged records. Email regex validation, phone formatting, and VAT format checks all execute in under 1ms per record, making them suitable for validating millions of rows in a single DuckDB query without external service dependencies.


🍪 Cookie Settings