Files
api/src/common/mobile.util.ts
T

20 lines
609 B
TypeScript
Raw Normal View History

/** Normalize Iranian mobile to 09xxxxxxxxx, or null if invalid. */
export function normalizeMobile(input?: string | null): string | null {
if (!input) return null;
let digits = String(input).replace(/\D/g, '');
if (digits.startsWith('98') && digits.length >= 12) {
digits = `0${digits.slice(2)}`;
}
if (digits.startsWith('9') && digits.length === 10) {
digits = `0${digits}`;
}
if (!/^09\d{9}$/.test(digits)) {
return null;
}
return digits;
}
export function displayName(firstName: string, lastName: string) {
return `${firstName} ${lastName}`.replace(/\s+/g, ' ').trim();
}