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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.