feat: add phone number normalization to Ethiopian E.164 format in CompanyProfileForm

This commit is contained in:
Marshal
2026-06-22 12:35:01 +00:00
parent 30b022356c
commit 39f2c99395
2 changed files with 35 additions and 9 deletions

View File

@@ -14,6 +14,24 @@ import "./phone-field.css";
export const isValidPhone = (value?: string | null): boolean =>
!!value && isValidPhoneNumber(value);
/**
* Normalize a raw (often eTrade) phone string to Ethiopian E.164 (+251…).
* eTrade returns local numbers like "0912345678" / "0355235416"; the phone
* input needs +251… to parse, so we drop a leading 0 and prepend +251. Numbers
* already in +… form, or that can't be coerced, are returned trimmed/as-is.
*/
export const toEthiopianE164 = (raw?: string | null): string => {
if (!raw) return "";
const trimmed = raw.trim();
if (trimmed.startsWith("+")) return trimmed.replace(/[^\d+]/g, "");
// Keep digits only, drop a single leading zero (national trunk prefix).
const digits = trimmed.replace(/\D/g, "").replace(/^0/, "");
if (!digits) return "";
// Already includes the 251 country code.
if (digits.startsWith("251")) return `+${digits}`;
return `+251${digits}`;
};
/**
* The text input rendered inside react-phone-number-input, styled to match the
* portal's Mantine fields (44px height, 10px radius, edr border). Must forward