jdubs edited this page Oct 21, 2016 · 1 revision

Table of Contents


Calculates the check digit for a supplied and valid Zip Code, Zip+4 or Zip+4 DPBC and formats the value for barcode font usage.


SpecName (constant) The variable containing the input to be converted. Proper EAN13 font must be applied in the template.

AlternateStartStopChar (multiple | optional) Optional value for stop and start character required by the barcode font. The default is ! and required by the Four51 recommended PostNet font.

ErrorMessage (multiple | optional) The error message to return when any error occurs.


This method follows the specifications set forth by the United States Postal Service. Within the method a test of the check digit calculation is performed. If the test fails an error will be returned to avoid any inaccurate barcodes from being rendered to the page. The "-" character is also replaced automatically. For example: "55555-1237" will be returned as "!5555512372!".

Source Code

public static void PostNet(string SpecName,object AlternateStartStopChar, object ErrorMessage)
		int total = 0;
		int remainder = 0;
		int checkdigit = 0;

		string postcode = Variable(SpecName).Value.Replace("-", "");

		IEnumerator chars = postcode.GetEnumerator();
		while (chars.MoveNext())
			total += Convert.ToInt32(chars.Current.ToString());

		remainder = total % 10;

		checkdigit = 10 - remainder;

		if ((total + checkdigit) % 10 != 0)
			throw new Exception("The calculation failed proofing");

		Variable(SpecName).Value = String.Format("{2}{0}{1}{2}",
			AlternateStartStopChar.ToString().Length > 0 ? AlternateStartStopChar.ToString() : "!");
	catch (Exception ex)
		throw new Four51ActionsException(ex.Message, (string)ErrorMessage);

Referenced Methods

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.