Validation Functions
Email, address, phone, and VAT validation APIs.
Quick Reference
| Function | Description | SQL Signature |
|---|---|---|
anofox_email_validate | Validate email | (email, mode) -> BOOLEAN |
anofox_phone_validate | Validate phone | (number, country) -> BOOLEAN |
anofox_vat_is_valid | Validate VAT format | (vat_id) -> BOOLEAN |
anofox_vat_verify_eu | Verify EU VIES | (vat_id) -> BOOLEAN |
anofox_address_validate | Validate address | (address) -> BOOLEAN |
anofox_postal_code_validate | Validate postal | (code, country) -> BOOLEAN |
Email Functions (3)
anofox_email_validate
Validate email using one of three modes.
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
email | VARCHAR | Yes | - | Email address to validate |
mode | VARCHAR | Yes | - | '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
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
code | VARCHAR | Yes | - | Postal code |
country | VARCHAR | Yes | - | 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
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
number | VARCHAR | Yes | - | Phone number (any format) |
country | VARCHAR | Yes | - | 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
| Function | Speed | Network | Cacheable |
|---|---|---|---|
| Email regex | <1ms | No | Yes |
| Email DNS | ~100ms | Yes | Yes |
| Email SMTP | ~500ms | Yes | No |
| Phone | ~5-50ms | No | No |
| VAT format | <1ms | No | Yes |
| VAT VIES | ~200ms | Yes | Yes |