Created
September 8, 2010 19:37
-
-
Save jmarnold/570695 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HelloWorldValidationRegistry : ValidationRegistry | |
{ | |
public HelloWorldValidationRegistry() | |
{ | |
AppliesTo | |
.ToThisAssembly(); | |
Models | |
.IncludeTypes(t => t.Namespace.StartsWith(typeof(ModelMarker).Namespace)) | |
.Exclude<ModelMarker>(); | |
this.UseValidationAttributes(); | |
this.InheritValidationRules(); | |
Rules | |
.IfProperty(p => p.Name.ToLower().Contains("email"), validate => validate.AsEmail()) | |
.IfProperty(p => p.Name.ToLower().Contains("phone"), validate => validate.AsPhoneNumber()) | |
.BuildDependenciesWith(ObjectFactory.GetInstance); | |
Extensions | |
.IncludedExtensionsInNamespaceContaining<HelloWorldValidationRegistry>(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class UserValidationExtension : IValidationRegistryExtension | |
{ | |
public void Configure(ValidationRegistry registry) | |
{ | |
registry | |
.Rules | |
.For<UserInputModel>() | |
.Require(u => u.Password) | |
.Require(u => u.ConfirmPassword) | |
.Compare(u => u.Password, u => u.ConfirmPassword); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment