Skip to main content

Validation Functions

Email, address, phone, and VAT validation APIs.

Quick Reference

FunctionDescriptionSQL Signature
anofox_email_validateValidate email(email, mode) -> BOOLEAN
anofox_phone_validateValidate phone(number, country) -> BOOLEAN
anofox_vat_is_validValidate VAT format(vat_id) -> BOOLEAN
anofox_vat_verify_euVerify EU VIES(vat_id) -> BOOLEAN
anofox_address_validateValidate address(address) -> BOOLEAN
anofox_postal_code_validateValidate postal(code, country) -> BOOLEAN

Email Functions (3)

anofox_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_email_validate(email, 'regex') as syntax_valid,
anofox_email_validate(email, 'dns') as domain_valid,
anofox_email_validate(email, 'smtp') as mailbox_valid
FROM customers;

anofox_email_extract_domain

Extract domain from email address.

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

anofox_email_normalize

Normalize email (lowercase, trim whitespace).

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

Address Functions (4)

anofox_address_validate

Validate street address format.

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

anofox_postal_code_validate

Validate postal code for country.

Parameters

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

Example

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

anofox_address_get_state

Extract state or province.

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

anofox_address_get_city

Extract city.

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

Phone Functions (9)

anofox_phone_format

Format phone number to standard format.

Parameters

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

Example

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

anofox_phone_validate

Validate phone number for country.

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

anofox_phone_get_country_code

Extract country code.

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

anofox_phone_is_mobile

Check if mobile number.

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

anofox_phone_get_carrier

Get carrier/operator name.

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

anofox_phone_normalize

Normalize to E.164 format.

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

VAT Functions (10)

anofox_vat_is_valid

Validate VAT ID format.

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

anofox_vat_get_country

Extract country code from VAT ID.

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

anofox_vat_verify_eu

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

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

anofox_vat_get_company_name

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

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

anofox_vat_format

Format VAT ID to country standard.

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

anofox_vat_is_eu_member

Check if country is EU member.

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

anofox_vat_get_standard_rate

Get standard VAT rate for country.

SELECT
anofox_vat_get_standard_rate('DE'), -- 0.19 (19%)
anofox_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

🍪 Cookie Settings