Skip to Main Content
Advanced TypeScript Programming Projects
book

Advanced TypeScript Programming Projects

by Peter O'Hanlon
July 2019
Intermediate to advanced content levelIntermediate to advanced
416 pages
10h 6m
English
Packt Publishing
Content preview from Advanced TypeScript Programming Projects

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. ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learn TypeScript 3 by Building Web Applications

Learn TypeScript 3 by Building Web Applications

Sebastien Dubois, Alexis Georges

Publisher Resources

ISBN: 9781789133042Supplemental Content