Files
hope-events/frontend/src/lib/phone.ts
T
joshua 3d381944d2 Initial commit
Next.js + Express event management app for Hope Family Church.
2026-07-23 15:26:47 +02:00

23 lines
746 B
TypeScript

/**
* South African phone number utilities (mirrors backend/src/utils/whatsapp.js logic).
*/
/**
* Normalise a raw phone input to the international SA format (27XXXXXXXXX).
* Returns null if the input is not a valid SA mobile number.
*/
export function normalizeZAPhone(raw: string | null | undefined): string | null {
if (!raw) return null;
let digits = raw.replace(/\D/g, '');
if (digits.startsWith('0') && digits.length === 10) digits = '27' + digits.slice(1);
if (/^27\d{9}$/.test(digits)) return digits;
return null;
}
/**
* Returns true when the value is a valid SA mobile number (any common format).
*/
export function isValidZAPhone(raw: string | null | undefined): boolean {
return normalizeZAPhone(raw) !== null;
}