Click here to Skip to main content
15,867,686 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 Asp.net 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')]
Posted
Updated 7-Dec-15 23:40pm
v2
Comments
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;
}
else
{
return new ValidationResult("Please Enter a Valid Email.");
}
}
else
{
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:

http://www.dotnet-tricks.com/Tutorial/mvc/H1VF301212-MVC4-Registration-form-with-Client-and-Server-Side-Validation.html

 
Share this answer
 
 
Share this answer
 

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