Validating the address

Our address validation is going to use the MinLengthValidator and RegularExpressionValidator validators:

export class AddressValidation implements IValidation {  private readonly minLengthValidator : MinLengthValidator = new MinLengthValidator(5);  private readonly zipCodeValidator : RegularExpressionValidator     = new RegularExpressionValidator("^[0-9]{5}(?:-[0-9]{4})?$");}

The minimum length validation is simple enough, but the regular expression can be intimidating if you have never seen this type of syntax before. Before we look at our validation code, we will break down what the regular expression is doing.

The first character, ^, tells us that our validation is going to start at the very beginning of the string. ...

Get Advanced TypeScript Programming Projects 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.