July 2019
Intermediate to advanced
416 pages
10h 6m
English
The name validation is the simplest piece of validation we are going to write. This validation assumes that we have a minimum of one letter for the first name and two letters for the last name:
export class PersonValidation implements IValidation { private readonly firstNameValidator : MinLengthValidator = new MinLengthValidator(1); private readonly lastNameValidator : MinLengthValidator = new MinLengthValidator(2); public Validate(state: IPersonState, errors: string[]): void { if (!this.firstNameValidator.IsValid(state.FirstName)) { errors.push("The first name is a minimum of 1 character"); } if (!this.lastNameValidator.IsValid(state.FirstName)) { errors.push("The last name is a minimum of 2 characters"); } }}
Read now
Unlock full access