Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 2x 2x 2x 5x 5x | /**
* Shared validation for the city values that /api/weather and /api/news accept.
*
* Kept in one place because the two routes take the same values from the same UI:
* they drifted apart once before, and a rule tightened in one route but not the
* other means a city that renders weather but silently fails to load its news.
*/
// '+' is allowed because the UI sends "city+region" pairs, e.g. "limerick+ireland".
const CITY_NAME = /^[a-zA-ZÀ-ÿ\s+-]+$/;
const MIN_LENGTH = 2;
const MAX_LENGTH = 50;
export const isValidCityName = (city: string): boolean =>
city.length >= MIN_LENGTH && city.length <= MAX_LENGTH && CITY_NAME.test(city);
|