I need a regular Expression for Validating City textBox, the city textbox field accepts only Letters, spaces and dashes(-).
See Question&Answers more detail:osI need a regular Expression for Validating City textBox, the city textbox field accepts only Letters, spaces and dashes(-).
See Question&Answers more detail:osThis answer assumes that the letters which @Manaysah refers to also encompasses the use of diacritical marks. I've added the single quote ' since many names in Canada and France have it. I've also added the period (dot) since it's required for contracted names.
Building upon @UIDs answer I came up with,
^([a-zA-Zu0080-u024F]+(?:. |-| |'))*[a-zA-Zu0080-u024F]*$
The list of cities it accepts:
Toronto St. Catharines San Fransisco Val-d'Or Presqu'ile Niagara on the Lake Niagara-on-the-Lake München toronto toRonTo villes du Québec Provence-Alpes-C?te d'Azur ?le-de-France Kópavogur Gareab?r Saueárkrókur Torláksh?fn
And what it rejects:
A----B ------ ******* && () // \
I didn't add in the use of brackets and other marks since it didn't fall within the scope of this question.
I've stayed away from s for whitespace. Tabs and line feeds aren't part of a city name and shouldn't be used in my opinion.