import { TextField } from "@mui/material"; import { styleTextSelectRight } from "@/mui"; // تابع تبدیل اعداد فارسی به انگلیسی const convertPersianToEnglish = (str) => { const persianNumbers = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹']; const arabicNumbers = ['٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩']; let result = str; for (let i = 0; i < 10; i++) { const regex = new RegExp(persianNumbers[i], 'g'); result = result.replace(regex, i.toString()); const arabicRegex = new RegExp(arabicNumbers[i], 'g'); result = result.replace(arabicRegex, i.toString()); } return result; }; function Field({ title, error, placeholder, inputProps, type, dir, value, updateState, }) { const handleChange = (e) => { let inputValue = e.target.value; // اگر type تلفن است، فقط اعداد انگلیسی را قبول کن if (type === "tel") { // ابتدا اعداد فارسی و عربی را به انگلیسی تبدیل کن inputValue = convertPersianToEnglish(inputValue); // فقط اعداد انگلیسی را نگه دار inputValue = inputValue.replace(/[^0-9]/g, ''); } updateState(inputValue); }; return ( ); } export default Field;