官术网_书友最值得收藏!

Validating the name

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");
}
}
}

主站蜘蛛池模板: 镇康县| 中西区| 射洪县| 马关县| 娄烦县| 万州区| 特克斯县| 红桥区| 泰兴市| 四平市| 会昌县| 宁明县| 含山县| 红桥区| 沙坪坝区| 克东县| 宁南县| 上饶县| 盈江县| 满洲里市| 河曲县| 德阳市| 中方县| 左贡县| 徐汇区| 丹阳市| 陵川县| 汉沽区| 思南县| 永兴县| 虎林市| 高青县| 张家口市| 织金县| 灯塔市| 宾阳县| 海原县| 民权县| 夹江县| 五大连池市| 永康市|