Mercurial > silverbladetech
annotate SilverlightValidation/SilverlightValidation.PL/Validators/UserModelValidator.cs @ 103:8cb4f36717e9
Fake it easy dll added
author | stevenhollidge <stevenhollidge@hotmail.com> |
---|---|
date | Sun, 06 May 2012 12:14:53 +0100 |
parents | db05a55e3536 |
children |
rev | line source |
---|---|
58 | 1 using System; |
2 using FluentValidation; | |
3 using SilverlightValidation.Interfaces; | |
4 | |
5 namespace SilverlightValidation.Validators | |
6 { | |
7 public class UserModelValidator : AbstractValidator<IUserModel> | |
8 { | |
102
db05a55e3536
INPC tests added
stevenhollidge <stevenhollidge@hotmail.com>
parents:
96
diff
changeset
|
9 private UserModelValidator() |
58 | 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 } | |
102
db05a55e3536
INPC tests added
stevenhollidge <stevenhollidge@hotmail.com>
parents:
96
diff
changeset
|
35 |
db05a55e3536
INPC tests added
stevenhollidge <stevenhollidge@hotmail.com>
parents:
96
diff
changeset
|
36 public static UserModelValidator Create() |
db05a55e3536
INPC tests added
stevenhollidge <stevenhollidge@hotmail.com>
parents:
96
diff
changeset
|
37 { |
db05a55e3536
INPC tests added
stevenhollidge <stevenhollidge@hotmail.com>
parents:
96
diff
changeset
|
38 return new UserModelValidator(); |
db05a55e3536
INPC tests added
stevenhollidge <stevenhollidge@hotmail.com>
parents:
96
diff
changeset
|
39 } |
58 | 40 } |
41 } |