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

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

主站蜘蛛池模板: 三原县| 东方市| 莱阳市| 晋州市| 桃江县| 阆中市| 洛隆县| 徐水县| 中西区| 延吉市| 光泽县| 宁化县| 上虞市| 文水县| 阿拉尔市| 吉木萨尔县| 昌图县| 尉氏县| 杨浦区| 深水埗区| 涪陵区| 常州市| 阿图什市| 津市市| 邢台市| 桐柏县| 突泉县| 商水县| 图木舒克市| 西乌珠穆沁旗| 玛多县| 洪洞县| 皋兰县| 平谷区| 古田县| 龙岩市| 宜黄县| 保康县| 安宁市| 镇原县| 安顺市|