Files
gao-customer-h5/src/utils/telephone.ts
T
2026-08-03 01:27:46 +08:00

26 lines
708 B
TypeScript

export function normalizeTelephone(value?: string): string {
if (!value) {
return "";
}
const trimmedValue = value.trim();
if (!trimmedValue) {
return "";
}
const normalizedValue = trimmedValue.startsWith("+")
? `+${trimmedValue.slice(1).replace(/\D/g, "")}`
: trimmedValue.replace(/\D/g, "");
return normalizedValue === "+" ? "" : normalizedValue;
}
export function canDialTelephone(value?: string): boolean {
const normalizedValue = normalizeTelephone(value);
return 2 < normalizedValue.replace("+", "").length;
}
export function buildTelephoneURL(value?: string): string {
const normalizedValue = normalizeTelephone(value);
return normalizedValue ? `tel:${normalizedValue}` : "";
}