c# - Min age check custom validation for MVC 4.5 -


i need advice on custom validation mvc 4.5 using own custom data annotations

i validating someones age when registering website.

i require these fields pass validator.

(date) date of birth (date)event start date (int)min age value 

i store min age , event start date in web.config. can customized. if user's age not old enough when checking event date cannot register.

how go doing this? have checked examples can't seem head around it.

thanks...

creating own validation attribute way go , easy achieve. create 1 need create class implements validationattribute

example

public class minageattribute : validationattribute {     protected override validationresult isvalid(object value, validationcontext validationcontext)     {        // validation checks here         var result = new validationresult("sorry not old enough");          return result;     }  

you override isvalid method validation logic, returning validationresult


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -