change style & add space & validation number in register page
This commit is contained in:
+23
-1
@@ -105,4 +105,26 @@ export const addLabelToList = (list) =>
|
||||
...item,
|
||||
label: item.name
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
export const formatPhoneNumber = (input) => {
|
||||
const digits = input.replace(/\D/g, '');
|
||||
const trimmed = digits.substring(0, 9);
|
||||
const match = trimmed.match(/^(\d{0,2})(\d{0,3})(\d{0,4})$/);
|
||||
if (!match) return trimmed;
|
||||
return [match[1], match[2], match[3]].filter(Boolean).join(' ');
|
||||
};
|
||||
|
||||
export function validatePhoneNumber(input) {
|
||||
const digits = input.replace(/\D/g, '');
|
||||
|
||||
if (!digits) {
|
||||
return { valid: false, error: 'شماره موبایل نمیتواند خالی باشد.' };
|
||||
}
|
||||
|
||||
if (digits.length !== 9) {
|
||||
return { valid: false, error: 'شماره موبایل باید دقیقا 11 رقم باشد.' };
|
||||
}
|
||||
|
||||
return { valid: true, error: null };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user