July 2019
Intermediate to advanced
416 pages
10h 6m
English
The phone number validation is going to be broken down into two parts. First, we validate that there is an entry for the phone number. Then, we validate to ensure that it is in the correct format using a regular expression. Before we analyze the regular expression, let's see what this validation class looks like:
export class PhoneValidation implements IValidation { private readonly regexValidator : RegularExpressionValidator = new RegularExpressionValidator(`^(?:\\((?:[0-9]{3})\\)|(?:[0-9]{3}))[-. ]?(?:[0-9]{3})[-. ]?(?:[0-9]{4})$`); private readonly minLengthValidator : MinLengthValidator = new MinLengthValidator(1); public Validate(state : IPersonState, errors : string[]) : void { if (!this.minLengthValidator.IsValid(state.PhoneNumber)) ...Read now
Unlock full access