This commit is contained in:
Li1304553726 2025-11-17 19:58:07 +08:00
commit 041c26283b
1 changed files with 4 additions and 14 deletions

View File

@ -24,26 +24,16 @@ export function WeatherSearchForm() {
setInputError('请输入城市名称'); setInputError('请输入城市名称');
return; return;
} }
if (trimmedCity.length < 2) { if (trimmedCity.length <2) {
setInputError('请输入至少2个字符'); setInputError('请输入至少2个字符');
return; return;
} }
if (!/^[a-zA-Z\s]+$/.test(trimmedCity)) { if (!/^[\u4e00-\u9fa5a-zA-Z\s-]+$/.test(trimmedCity)) {
setInputError('请输入字母和空格'); setInputError('请输入有效的城市名称');
return; return;
} }
await searchWeather(trimmedCity); await searchWeather(trimmedCity);
if (trimmedCity.length < 2) {
setInputError('请输入至少2个字符');
return;
}
if (!/^[a-zA-Z\s]+$/.test(trimmedCity)) {
setInputError('请输入字母和空格');
return;
}
await searchWeather(trimmedCity);
} }
return ( return (