Mercurial > silverbladetech
comparison SilverlightGlimpse/SilverlightValidation/Validators/UserModelValidator.cs @ 69:a0bcd783e612
Latest work
author | Steven Hollidge <stevenhollidge@hotmail.com> |
---|---|
date | Mon, 23 Apr 2012 11:06:10 +0100 |
parents | |
children | dd6bcd2535b6 |
comparison
equal
deleted
inserted
replaced
68:81337ebf885a | 69:a0bcd783e612 |
---|---|
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 } |