mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-07 21:15:41 +00:00
feat: add phone number normalization to Ethiopian E.164 format in CompanyProfileForm
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user