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

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

主站蜘蛛池模板: 祁门县| 莎车县| 宁安市| 富源县| 弋阳县| 涿鹿县| 鄂温| 辛集市| 内乡县| 保德县| 云南省| 西华县| 藁城市| 鄄城县| 明水县| 南充市| 开鲁县| 江安县| 疏附县| 晋中市| 龙井市| 马龙县| 乌苏市| 应城市| 灵川县| 恭城| 会昌县| 宜黄县| 章丘市| 广丰县| 鞍山市| 龙泉市| 福清市| 克什克腾旗| 城口县| 衡东县| 即墨市| 调兵山市| 佛冈县| 霍邱县| 新晃|