Reputation: 975
var cityRegex = /^[a-zA-z] ?([a-zA-z]|[a-zA-z] )*[a-zA-z]$/;
is what I tried.
But it errors when you type in a city like "St. Petersburg."
Update: Seems almost like a lost cause. Too many oddly-named cities out there with numbers, dashes, apostrophes, periods, etc.
Upvotes: 3
Views: 6043
Reputation: 4021
If the comments don't make it clear enough, this is not something that can realistically be validated by regex. The correct thing to do here is just accept that there will be some bad data inputted and move along. If you really need the city to exist and you think that this javascript validation will help you, you are sorely mistaken.
In answer to your question, the correct validation here is:
.*
Upvotes: 5