Initial commit
Next.js + Express event management app for Hope Family Church.
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
Reference in New Issue
Block a user