Mercurial > silverbladetech
comparison SilverlightValidation/SilverlightValidation.PL/Validators/UserModelValidator.cs @ 96:188f8b366e87
Unit test project correctly setup as normal class library DLL.
author | stevenhollidge <stevenhollidge@hotmail.com> |
---|---|
date | Sat, 05 May 2012 13:29:56 +0100 |
parents | SilverlightValidation/SilverlightValidation/Validators/UserModelValidator.cs@241e2f22ed3c |
children | db05a55e3536 |
comparison
equal
deleted
inserted
replaced
95:64e9903703a3 | 96:188f8b366e87 |
---|---|
1 using System; | |
2 using FluentValidation; | |
3 using SilverlightValidation.Interfaces; | |
4 | |
5 namespace SilverlightValidation.Validators | |
6 { | |
7 public class UserModelValidator : AbstractValidator<IUserModel> | |
8 { | |
9 public UserModelValidator() | |
10 { | |
11 RuleFor(x => x.Username) | |
12 .Length(3, 8) | |
13 .WithMessage("Must be between 3-8 characters."); | |
14 | |
15 RuleFor(x => x.Password) | |
16 .Matches(@"^\w*(?=\w*\d)(?=\w*[a-z])(?=\w*[A-Z])\w*$") | |
17 .WithMessage("Must contain lower, upper and numeric chars."); | |
18 | |
19 RuleFor(x => x.Email) | |
20 .EmailAddress() | |
21 .WithMessage("A valid email address is required."); | |
22 | |
23 RuleFor(x => x.DateOfBirth) | |
24 .Must(BeAValidDateOfBirth) | |
25 .WithMessage("Must be within 100 years of today."); | |
26 } | |
27 | |
28 private bool BeAValidDateOfBirth(DateTime? dateOfBirth) | |
29 { | |
30 if (dateOfBirth == null) return false; | |
31 if (dateOfBirth.Value > DateTime.Today || dateOfBirth < DateTime.Today.AddYears(-100)) | |
32 return false; | |
33 return true; | |
34 } | |
35 } | |
36 } |