MultiUsersSalesSystem / utils /customerNormalization.js
Mahmoud7456's picture
Upload 71 files
1e65df5 verified
Raw History Blame Contribute Delete
725 Bytes
export const normalizeCustomerName = (value = "") => {
return String(value || "")
.trim()
.replace(/\s+/g, " ")
.replace(/[\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06ED]/g, "")
.replace(/ـ/g, "")
.replace(/[أإآٱ]/g, "ا")
.replace(/ؤ/g, "و")
.replace(/ئ/g, "ي")
.replace(/ى/g, "ي")
.toLowerCase();
};
export const normalizeCustomerPhone = (value = "") => {
let digits = String(value || "").replace(/\D/g, "");
if (!digits) return "";
if (digits.startsWith("0") && digits.length === 11) {
digits = `20${digits.slice(1)}`;
} else if (digits.length === 10 && digits.startsWith("1")) {
digits = `20${digits}`;
}
return digits;
};