Home
Manage Your Code
Snippet: Valid US Postal code format Regex (C#)
Title: Valid US Postal code format Regex Language: C#
Description: Allows 5 digit, 5+4 digit and 9 digit zip codes Views: 249
Author: Steve Vasquez Date Added: 8/8/2008
Copy Code  
1
2public static bool IsValidUSZip(string num)
3{
4    // Allows 5 digit, 5+4 digit and 9 digit zip codes

5    string pattern = @"^(\d{5}-\d{4}|\d{5}|\d{9})$";
6    Regex match = new Regex(pattern);
7    return match.IsMatch(num);
8}