Compare commits

..

No commits in common. "b7d7a3963aae6c852119e5088053f1fcab41ba8b" and "f8138c7ffb600ce8eec896b083efd2f75142ef26" have entirely different histories.

1 changed files with 14 additions and 4 deletions

View File

@ -24,16 +24,26 @@ export function WeatherSearchForm() {
setInputError('请输入城市名称'); setInputError('请输入城市名称');
return; return;
} }
if (trimmedCity.length <2) { if (trimmedCity.length < 2) {
setInputError('请输入至少2个字符'); setInputError('请输入至少2个字符');
return; return;
} }
if (!/^[\u4e00-\u9fa5a-zA-Z\s-]+$/.test(trimmedCity)) { if (!/^[a-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 (