[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 267
  • Last Modified:

check Zipcode in a string

How can I check if a string contain zipcode in Regex?
san francisco, ca 91000  or san francisco ca 91000

I want to make it san francisco, CA 91000

String ZipRegex = @"^\d{5}$";

  String ZipRegex = @"^\d{5}$";
   if(Regex.IsMatch(ZipTextBox.Text, ZipRegex))
      ResultLabel.Text = "ZIP is valid!";
      ResultLabel.Text = "ZIP is invalid!";

1 Solution
käµfm³d 👽Commented:
Try this:

String ZipRegex = @"\b\d{5}\b";

Open in new window

Be advised:  this will check that a string of 5 digits occurs anywhere in the string, but not that it is necessarily a zip code.

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now