Using Sitecore 8.2
I have a form and I'm trying to add custom validation to the email field to block forbidden domains. I created the validation item in Sitecore and added it to my field:
and I created the corresponding class in my project:
namespace Example.Library.WebForms.Validators
{
public class EmailValidation : FormCustomValidator
{
public EmailValidation()
{
this.ServerValidate += this.ValidateEmailAddress;
}
private void ValidateEmailAddress(object source, ServerValidateEventArgs args)
{
var blacklistFolder = Sitecore.Context.Database.GetItem(exampleConstants.exampleBlacklistFolder);
var domains = blacklistFolder.Axes.GetDescendants().Select(x => x.GlassCast<IRestricted_Domain>());\
var email = args.Value;
foreach (var dom in domains)
{
var domain = dom.Domain;
if (email.ToLower().EndsWith(domain.ToLower()))
{
args.IsValid = false;
}
}
}
}
}
But it doesn't seem to be doing anything, and when I debug and attach to the ValidateEmailAddress method it never hits it. What am I missing?
EDIT: I changed the Assembly from Example.Library to Example.Library.dll but it's still not hitting it.