Regular Expressions for City name

regex for city and state
regular expression for address in c#
regular expression for state validation
regex tester
regular expression examples
regular expression match
java compliant regular expression
zip code regex

I need a regular Expression for Validating City textBox, the city textbox field accepts only Letters, spaces and dashes(-).


This can be arbitrarily complex, depending on how precise you need the match to be, and the variation you're willing to allow.

Something fairly simple like ^[a-zA-Z]+(?:[\s-][a-zA-Z]+)*$ should work.

warning: This does not match cities like München, etc, but here you basically need to work with the [a-zA-Z] part of the expression, and define what characters are allowed for your particular case.

Keep in mind that it also allows for something like San----Francisco, or having several spaces.

Translates to something like: 1 or more letters, followed by a block of: 0 or more spaces or dashes and more letters, this last block can occur 0 or more times.

Weird stuff in there: the ?: bit. If you're not familiarized with regexes, it might be confusing, but that simply states that the piece of regex between parenthesis, is not a capturing group (I don't want to capture the part it matches to reuse later), so the parenthesis are only used as to group the expression (and not to capture the match).

"New York" // passes

"San-Francisco" // passes

"San Fran Cisco" // passes (sorry, needed an example with three tokens)

"Chicago" // passes

"  Chicago" // doesn't pass, starts with spaces

"San-" // doesn't pass, ends with a dash

Validate city name : Regular Expression « Development Class « C# , Validate city name using System; using System.Text.RegularExpressions; class RegexSubstitution { public static void Main() { string text = "124 street"; if ( !Regex​  Gets the group name that corresponds to the specified group number. 29. Indicates whether the regular expression specified in the Regex constructor finds a match in the input string.


This 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-Z\u0080-\u024F]+(?:. |-| |'))*[a-zA-Z\u0080-\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
Garðabær
Sauðárkrókur
Þorlá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.

Validate city and state : Regular Expressions « Development « Java , Validate city and state : Regular Expressions « Development « Java Tutorial. Regular Expressions. 6.32.1. Validate the first name and last name. 6.32.2. This regular expression using named groups returns semantic tokens and is designed for Australian addresses in one line. Any part of an address may be omitted, as long as parts are in minor to major order. It should not be difficult to modify the regular express for analysing multi-line addresses.


Adding my answer if anybody needs its while searching for Regex for City Names, Like I did

Please use this :

^[a-zA-Z\u0080-\u024F\s\/\-\)\(\`\.\"\']+$

As many city names contains dashes, such as Soddy-Daisy, Tennessee, or special characters like, ñ in La Cañada Flintridge, California

Hope this helps!

Search Results: 22 regular expressions found., City - Proper case city name. State - State With a little modification, this regex may work for other postal address formats in minor to major order. Best REGEX for first/last name validation? Ask Question Asked 5 years, 10 months ago. Browse other questions tagged regular-expressions or ask your own question.


Belgian City Names, In order to match the city and state using regular expression, we use the matches method in Java. The java.lang.String.matches() method  The following example illustrates the use of character escapes in a regular expression. It parses a string that contains the names of the world's largest cities and their populations in 2009. Each city name is separated from its population by a tab (\t) or a vertical bar (| or \u007c). Individual cities and their populations are separated from each other by a carriage return and line feed.


^[a-zA-Z\- ]+$

Also this might be useful http://www.cheatography.com/davechild/cheat-sheets/regular-expressions/

Validate city and state with Java Regular Expressions, CoffeeCup Forums - RegEx for City, State and Zip - I'm working with the web form builder version 2.3, build 5217 and trying to build a custom  The thing I like about this is that the last name is always after the first name, so if you're going to enter this matched groups into a database, and the name is John M. Smith, the 1st group will be John M., and the 2nd group will be Smith.


RegEx for City, State and Zip, I need to set a location field to accept only format "City - ST" where City is the city name (that may contain a-z A-Z space and other characters  The following regular expression can be used for the above purpose ^[a-zA-Z\s]+$


Regular Expression (Regex) for "City - State" / format "City, City Name Regex. Category: Location. Purpose: Identifies requests by whether they originate from a city whose name matches the pattern defined by a  A regular expression is a pattern that the regular expression engine attempts to match in input text. A pattern consists of one or more character literals, operators, or constructs. For a brief introduction, see .NET Regular Expressions. Each section in this quick reference lists a particular category


City Name Regex, I want to Validate UserName and City field like this that UserCan not enter number,+@#$ characters any help to make thir regular expression  Even if you find an appropriate regular expression (maybe using Unicode character properties), this wouldn’t prevent users from entering pseudo-names like John Doe, Max Mustermann (there even is a person with that name), Abcde Fghijk or Ababa Bebebe.