diff --git a/app/components/WeatherSearchForm.tsx b/app/components/WeatherSearchForm.tsx index 7b7b746..dcd6ec3 100644 --- a/app/components/WeatherSearchForm.tsx +++ b/app/components/WeatherSearchForm.tsx @@ -24,26 +24,16 @@ export function WeatherSearchForm() { setInputError('请输入城市名称'); return; } - if (trimmedCity.length < 2) { + if (trimmedCity.length <2) { setInputError('请输入至少2个字符'); return; } - if (!/^[a-zA-Z\s]+$/.test(trimmedCity)) { - setInputError('请输入字母和空格'); + if (!/^[\u4e00-\u9fa5a-zA-Z\s-]+$/.test(trimmedCity)) { + setInputError('请输入有效的城市名称'); return; } await searchWeather(trimmedCity); - - if (trimmedCity.length < 2) { - setInputError('请输入至少2个字符'); - return; - } - - if (!/^[a-zA-Z\s]+$/.test(trimmedCity)) { - setInputError('请输入字母和空格'); - return; - } - await searchWeather(trimmedCity); + } return ( diff --git a/app/routes/weather.tsx b/app/routes/weather.tsx index c8ce90a..8b26a6b 100644 --- a/app/routes/weather.tsx +++ b/app/routes/weather.tsx @@ -2,7 +2,7 @@ import React, {useEffect} from 'react'; import { Loader2 } from 'lucide-react'; -import { WeatherCard } from '@/components/weather/WeatherCard'; +import { WeatherCard } from '@/components/WeatherCard'; import { useWeatherStore } from '@/store/weatherStore'; import {toast} from "sonner";