AI OnAI Off
Hi Joseph,
I don't know that this is known bug or not but you can create your custom Validation attribute and use that, instead of this.
public class CustomEmailAddressAttribute : DataTypeAttribute
{
private static readonly Regex ValidationRegex = new Regex(@"^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$", RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase);
public EmailAddressAttribute() : base(DataType.EmailAddress)
{
}
public override bool IsValid(object value)
{
if (string.IsNullOrEmpty(value))
{
return true;
}
return ((value is string input) && (ValidationRegex.Match(input).Length > 0));
}
}
Thanks
Ravindra
You can try this quick fix suggested by Jake
Or, log a bug to episerver support (if not already).
When a string property is decorated with an EmailAddressAttribute validation fails when removing the address. This occurs on a fresh Alloy site with all the latest updates.
How to reproduce:
Here validation fails with: The Email field is not a valid e-mail address.
Sent via Dojo to the server in the post body is: {"id":"113_116","properties":{"email":"\"\""},"action":513}
As an editor this can be worked around by leaving the property blank, switching to another property and changing that after which validation succeeds and nothing is sent for the property.
Is this a known bug? Is there a fix available?