feat(userAccount): add validation for Iranian national code and update input handling
This commit is contained in:
+15
-1
@@ -272,8 +272,8 @@ export const handleTimeExpiresToken = (expires_in) => {
|
||||
};
|
||||
|
||||
export const removeAdditionalKeysDashboard = (information) => {
|
||||
// فقط متادیتای سمت فرانت حذف میشود؛ national_code باید ارسال شود تا قابل ثبت/آپدیت باشد.
|
||||
const {
|
||||
national_code,
|
||||
changed,
|
||||
created,
|
||||
id,
|
||||
@@ -709,3 +709,17 @@ export function changeNumToDefault(str) {
|
||||
.replace(/[٠-٩]/g, d => "٠١٢٣٤٥٦٧٨٩".indexOf(d));
|
||||
}
|
||||
|
||||
|
||||
// اعتبارسنجی کد ملی ایران: ۱۰ رقم + الگوریتم رقم کنترلی.
|
||||
export const isValidIranNationalCode = (input) => {
|
||||
if (!input) return false;
|
||||
const code = String(input).replace(/\D/g, "");
|
||||
if (!/^\d{10}$/.test(code)) return false;
|
||||
// کدهای با ارقام یکسان (مثل 0000000000) نامعتبرند
|
||||
if (/^(\d)\1{9}$/.test(code)) return false;
|
||||
const check = +code[9];
|
||||
let sum = 0;
|
||||
for (let i = 0; i < 9; i++) sum += +code[i] * (10 - i);
|
||||
const r = sum % 11;
|
||||
return r < 2 ? check === r : check === 11 - r;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user