fix(leads): keep Persian digits when saving contact-form phones
Mixed Persian and Latin digits were stripped down to the Latin part, so some website leads stored a truncated mobile. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,19 +1,29 @@
|
|||||||
export function emptyToNull(value?: string | null): string | null {␍
|
export function emptyToNull(value?: string | null): string | null {
|
||||||
if (value == null) return null;␍
|
if (value == null) return null;
|
||||||
const trimmed = value.trim();␍
|
const trimmed = value.trim();
|
||||||
return trimmed.length ? trimmed : null;␍
|
return trimmed.length ? trimmed : null;
|
||||||
}␍
|
}
|
||||||
␍
|
|
||||||
export function normalizeEmail(value?: string | null): string | null {␍
|
export function normalizeEmail(value?: string | null): string | null {
|
||||||
const v = emptyToNull(value);␍
|
const v = emptyToNull(value);
|
||||||
return v ? v.toLowerCase() : null;␍
|
return v ? v.toLowerCase() : null;
|
||||||
}␍
|
}
|
||||||
␍
|
|
||||||
/** Keep digits and leading + for Iranian/international numbers. */␍
|
const FA_DIGITS = '۰۱۲۳۴۵۶۷۸۹';
|
||||||
export function normalizePhone(value?: string | null): string | null {␍
|
const AR_DIGITS = '٠١٢٣٤٥٦٧٨٩';
|
||||||
const v = emptyToNull(value);␍
|
|
||||||
if (!v) return null;␍
|
/** ارقام فارسی و عربی را به لاتین برمیگرداند تا از شماره حذف نشوند. */
|
||||||
const cleaned = v.replace(/[^\d+]/g, '');␍
|
function latinDigits(value: string): string {
|
||||||
return cleaned.length ? cleaned : null;␍
|
return value.replace(/[۰-۹٠-٩]/g, (ch) => {
|
||||||
}␍
|
const fa = FA_DIGITS.indexOf(ch);
|
||||||
␍
|
return String(fa >= 0 ? fa : AR_DIGITS.indexOf(ch));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Keep digits and leading + for Iranian/international numbers. */
|
||||||
|
export function normalizePhone(value?: string | null): string | null {
|
||||||
|
const v = emptyToNull(value);
|
||||||
|
if (!v) return null;
|
||||||
|
const cleaned = latinDigits(v).replace(/[^\d+]/g, '');
|
||||||
|
return cleaned.length ? cleaned : null;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user