Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8315453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:08:02+00:00 2026-06-08T21:08:02+00:00

I need a regular Expression for Validating City textBox, the city textbox field accepts

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T21:08:03+00:00Added an answer on June 8, 2026 at 9:08 pm

    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
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a regular expression or module for validating the website URL using Perl.
I need a basic regular expression for validating a url, such that: Both http://
i need a regular expression that checks if the multiline textbox has been left
I need a regular expression in .NET for validating words with alphabets and option
I need to validate textbox for validating phone number in C# allowing only hyphens(-)
Possible Duplicate: Validating an IP with regex I need the regular expression for finding
i need a regular expression to validate only allow -1 and all other positive
I need an regular expression that matches A.*C only if there's no B in
I need a regular expression that will not allow multiple special characters in a
I need a regular expression that will accept well-formed emails in several formats (see

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.