Skip to main content

Validation Functions

Email, address, phone, and VAT validation APIs.


Email Functions (3)

anofox_email_validate

Validate email using one of three modes.

Signature:

anofox_email_validate(email VARCHAR, mode VARCHAR)BOOLEAN

Parameters:

  • email: Email address to validate
  • mode: Validation mode
    • 'regex': Syntax only (<1ms)
    • 'dns': Domain check (~100ms)
    • 'smtp': Mailbox check (~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.

Signature:

anofox_email_extract_domain(email VARCHAR)VARCHAR

Returns: Domain name (e.g., 'example.com'), NULL if invalid email

Example:

SELECT
email,
anofox_email_extract_domain(email) as domain
FROM customers;

-- Output:
-- john@example.com | example.com
-- invalid.email | NULL

anofox_email_normalize

Normalize email (lowercase, trim whitespace).

Signature:

anofox_email_normalize(email VARCHAR)VARCHAR

Returns: Normalized email

Example:

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

Address Functions (4)

anofox_address_validate

Validate street address format.

Signature:

anofox_address_validate(address VARCHAR)BOOLEAN

Returns: TRUE if address format is valid

Example:

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

anofox_postal_code_validate

Validate postal code for country.

Signature:

anofox_postal_code_validate(code VARCHAR, country VARCHAR)BOOLEAN

Parameters:

  • code: Postal code
  • country: 2-letter country code (US, GB, DE, FR, etc.)

Returns: TRUE if valid for country

Example:

SELECT
anofox_postal_code_validate('90210', 'US'), -- true (US ZIP)
anofox_postal_code_validate('SW1A 1AA', 'GB'), -- true (UK postcode)
anofox_postal_code_validate('75001', 'FR'); -- true (French postal)

anofox_address_get_state

Extract state or province from address.

Signature:

anofox_address_get_state(address VARCHAR)VARCHAR

Returns: State/province code, NULL if not found

Example:

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

anofox_address_get_city

Extract city from address.

Signature:

anofox_address_get_city(address VARCHAR)VARCHAR

Returns: City name, NULL if not found

Example:

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.

Signature:

anofox_phone_format(number VARCHAR, country VARCHAR)VARCHAR

Parameters:

  • number: Phone number (any format)
  • country: 2-letter country code

Returns: Formatted number (e.g., '+1 555 0123'), NULL if invalid

Example:

SELECT
anofox_phone_format('+1-555-0123', 'US'), -- '+1 555 0123'
anofox_phone_format('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.

Signature:

anofox_phone_validate(number VARCHAR, country VARCHAR)BOOLEAN

Returns: TRUE if valid for country

Example:

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

anofox_phone_get_country_code

Extract country code from phone.

Signature:

anofox_phone_get_country_code(number VARCHAR)VARCHAR

Returns: Country code (e.g., 'US', 'GB'), NULL if unknown

Example:

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

anofox_phone_get_area_code

Extract area code.

Signature:

anofox_phone_get_area_code(number VARCHAR, country VARCHAR)VARCHAR

Returns: Area code, NULL if not applicable

Example:

SELECT anofox_phone_get_area_code('+1 555 0123', 'US');
-- Output: 555

anofox_phone_is_mobile

Check if phone is mobile number.

Signature:

anofox_phone_is_mobile(number VARCHAR, country VARCHAR)BOOLEAN

Returns: TRUE if mobile, FALSE if landline, NULL if unknown

Example:

SELECT
anofox_phone_is_mobile('+1 555 0123', 'US'), -- true
anofox_phone_is_mobile('+44 20 3946 0958', 'GB'); -- false

anofox_phone_get_carrier

Get carrier/operator name.

Signature:

anofox_phone_get_carrier(number VARCHAR, country VARCHAR)VARCHAR

Returns: Carrier name (e.g., 'Verizon', 'T-Mobile'), NULL if unknown

Example:

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

anofox_phone_normalize

Normalize to E.164 format (international standard).

Signature:

anofox_phone_normalize(number VARCHAR)VARCHAR

Returns: Normalized number in E.164 format (+1234567890)

Example:

SELECT anofox_phone_normalize('555-0123');
-- Output: +15550123 (if US context assumed)

anofox_phone_is_valid_length

Check if phone has valid length for country.

Signature:

anofox_phone_is_valid_length(number VARCHAR, country VARCHAR)BOOLEAN

Returns: TRUE if length is valid

Example:

SELECT anofox_phone_is_valid_length('+1-555-0123', 'US');
-- Output: true

anofox_phone_extract_digits

Extract digits only (remove formatting).

Signature:

anofox_phone_extract_digits(number VARCHAR)VARCHAR

Returns: Phone with only digits

Example:

SELECT anofox_phone_extract_digits('+1 (555) 0123-ext. 999');
-- Output: '15550123999'

VAT Functions (10)

anofox_vat_is_valid

Validate VAT ID format.

Signature:

anofox_vat_is_valid(vat_id VARCHAR)BOOLEAN

Returns: TRUE if format is valid for country

Example:

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

anofox_vat_get_country

Extract country code from VAT ID.

Signature:

anofox_vat_get_country(vat_id VARCHAR)VARCHAR

Returns: 2-letter country code, NULL if invalid

Example:

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

anofox_vat_verify_eu

Verify VAT ID in EU VIES system.

Signature:

anofox_vat_verify_eu(vat_id VARCHAR)BOOLEAN

Returns: TRUE if registered in VIES, NULL if error

Speed: ~200ms (network call)

Example:

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

anofox_vat_get_company_name

Get company name from VIES registration.

Signature:

anofox_vat_get_company_name(vat_id VARCHAR)VARCHAR

Returns: Company name as registered, NULL if not found

Speed: ~200ms (network call)

Example:

SELECT anofox_vat_get_company_name('DE123456789');
-- Output: 'Example GmbH' (or actual company name)

anofox_vat_format

Format VAT ID to country standard.

Signature:

anofox_vat_format(vat_id VARCHAR)VARCHAR

Returns: Formatted VAT ID

Example:

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

anofox_vat_has_valid_check_digit

Validate check digit only.

Signature:

anofox_vat_has_valid_check_digit(vat_id VARCHAR)BOOLEAN

Returns: TRUE if check digit is valid

Example:

SELECT anofox_vat_has_valid_check_digit('DE123456789');
-- Output: true

anofox_vat_is_registered

Check if VAT ID is currently registered (active).

Signature:

anofox_vat_is_registered(vat_id VARCHAR)BOOLEAN

Returns: TRUE if active, FALSE if inactive/deregistered

Speed: ~200ms (network call)

Example:

SELECT anofox_vat_is_registered('DE123456789');
-- Output: true

anofox_vat_get_address

Get registered address from VIES.

Signature:

anofox_vat_get_address(vat_id VARCHAR)VARCHAR

Returns: Address as registered, NULL if not found

Speed: ~200ms (network call)

Example:

SELECT anofox_vat_get_address('DE123456789');
-- Output: '123 Main Street, 10001 Berlin' (example)

anofox_vat_is_eu_member

Check if country is EU member.

Signature:

anofox_vat_is_eu_member(country_code VARCHAR)BOOLEAN

Returns: TRUE if EU member

Example:

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.

Signature:

anofox_vat_get_standard_rate(country_code VARCHAR)DECIMAL

Returns: Standard VAT rate (0.0-1.0)

Example:

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

Performance Characteristics

FunctionSpeedRequires NetworkCacheable
Email regex<1msNoYes
Email DNS~100msYesYes
Email SMTP~500msYesNo
Phone functions~5-50msNoNo
VAT format check<1msNoYes
VAT VIES check~200msYesYes
Address parsing~5msNoNo

Next Steps

🍪 Cookie Settings