I have tried some code but I cant share it here because it is confidential so please kindly help me
What I have tried:
Sample Code here
My Model Here
Class Customer
{
Hide Copy Code
Public string Name{get;set;}
Hide Copy Code
Public string City{get;set;}
[ELCustomValidation]
Hide Copy Code
Public string Email{get;set;}
}
EnterpriseLibrary Included Class
Public class ELCustomValidation : Validator
{
static readonly Regex Email=new regex("Regex Expr here");
Public ELCustomValidation(string MessageTemplet,string Tag):base(MessageTemplet,Tag)
{
}
protected override string DefaultMessageTemplate
{
get
{
throw new NotImplementedException ;
}
}
protected override void DoValidate(string objectToValidate,object currenttrget,string key,ValidationResult validationresult)
{
if(string.IsNullorEmpty(objectToValidate))
{return;}
Match match=Email.match(objectToValidate);
if(!match.success)
{
LogValidationResult(validationresult,"Email Id is not valid",currenttrget,key)
}
}
}
My AttributeClass here
[AttributeUsage(Attributetargets.property |Attributetargets.field)]
public class ELCustomeValidationAttribute : ValidatorAttribute
{
protected override Validatior DoCreateValidator(type target )
{
return ELCustomValidation("string",Tag);
}
}
And Error
A validation attribute of type ELcustomValidationAttribute can not be used to validate values