refactor: enhance phone number validation and input handling in Field and LogInPage components

This commit is contained in:
hamed
2025-11-17 15:09:25 +03:30
parent 5a58c13a4e
commit 2777db3b8c
4 changed files with 51 additions and 8 deletions
+7
View File
@@ -4,6 +4,7 @@ import { request } from "@/services/response";
import { InputAdornment, Button } from "@mui/material";
import Link from "next/link";
import { useState } from "react";
import { toast } from "react-toastify";
function LogInPage({ setIsSendMsg, num, setNum, setUuid, matchedCity, setStep }) {
const [error, setError] = useState({ valid: true, text: "" });
@@ -11,6 +12,12 @@ function LogInPage({ setIsSendMsg, num, setNum, setUuid, matchedCity, setStep })
const handleChange = (val) => {
const checkedNum = validatePhoneNumber(val);
// اگر کاراکتر غیر عددی بود، notification نشون بده
if (!checkedNum.valid && checkedNum.text === "فقط از اعداد انگلیسی استفاده کنید.") {
toast.error("فقط از اعداد انگلیسی استفاده کنید.");
}
setError(checkedNum);
setNum(val);
};