Building Your First Workflow Program

Here is a small code snippet that performs postal code validation, and it’s one you’ve no doubt written before or probably very much like one you would write if asked to do so:

protected const string USCode =
   @"^(\d{5}$)|(\d{5}$\-\d{4}$)";
protected const string CanadianCode =
   @"[ABCEGHJKLMNPRSTVXY]\d[A-Z] \d[A-Z]\d";

public static bool ValidatePostalCode(string str)
{
   return (Regex.IsMatch(str, USCode) ||
           Regex.IsMatch(str, CanadianCode));
}

Nothing special here—"Test the input string against a properly formatted US ZIP code or Canadian postal code and return false if improperly formatted for either postal system." It’s a nice chunk of procedural code, and in fact you could drop it into your ASP.NET validation ...

Get Microsoft® Windows® Workflow Foundation Step by Step now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.