Skip to main content

validateAddress

Validate customer address data against defined rules.

Import​

import { validateAddress } from "@evershop/evershop/customer/services";

Syntax​

validateAddress(address: Address): { valid: boolean; errors: string[] }

Parameters​

address

Type: Address

Address object to validate.

{
full_name?: string;
address_1?: string;
address_2?: string;
city?: string;
province?: string;
postcode?: string;
country?: string;
telephone?: string;
}

Return Value​

Returns validation result:

{
valid: boolean; // True if all rules pass
errors: string[]; // Array of error messages
}

Examples​

Basic Validation​

import { validateAddress } from "@evershop/evershop/customer/services";

const result = validateAddress({
full_name: 'John Doe',
address_1: '123 Main St',
province: 'CA',
postcode: '90001',
country: 'US'
});

if (result.valid) {
console.log('Address is valid');
} else {
console.error('Validation errors:', result.errors);
}

Notes​

  • Returns all validation errors
  • Extensible via addAddressValidationRule
  • Used internally by create/update functions

See Also​