Click here to Skip to main content
15,169,285 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need a custom attribute which supports client and server side validation in mvc 4.
i'm not getting how to right it for [Required] attribute ,can some one can provide some info.

Requirement is i need to give custom error messages ,which are placed in data base by calling a model function.

but [Required(ErrorMessages='here i'm not able to call a function')]
Updated 8-Dec-15 0:40am
Anisuzzaman Sumon 8-Dec-15 6:51am
Use custom Validator like this one

protected override ValidationResult IsValid(object value, ValidationContext validationContext)
if (value != null)
string email = value.ToString();

if (Regex.IsMatch(email, @"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}", RegexOptions.IgnoreCase))
return ValidationResult.Success;
return new ValidationResult("Please Enter a Valid Email.");
return new ValidationResult("" + validationContext.DisplayName + " is required");
harish55 8-Dec-15 7:11am
i tried this kind of example.but i'm not getting How can i integrate client side validation to this.
[no name] 8-Dec-15 13:04pm
Please go through below link that might help you:


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900