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
Post a Comment