I'm using the EmailAddressAttribute for use on my model.
The problem is when I use a (perfectly valid) e-mail address of
ó[email protected]
it says it is invalid.
Model:
public class ForgotPasswordViewModel
{
[Required]
[EmailAddress]
[Display(Name = "Email")]
public string Email { get; set; }
public CmsContentPagesModel PageCmsContent { get; set; }
public CmsContentPagesModel PageCmsContentInfoIcon { get; set; }
public CmsContentPagesModel PageCmsContentRightPanel { get; set; }
}
Is this an issue with the attribute, or do I somehow have to specify that French e-mails are okay?
Input box as rendered:
<div class="col-md-5">
<input class="form-control" data-val="true" data-val-email="The Email field is not a valid e-mail address." data-val-required="The Email field is required." id="Email" name="Email" type="text" value="" />
<span class="field-validation-valid text-danger" data-valmsg-for="Email" data-valmsg-replace="true"></span>
</div>
I've also extracted the regex from the client-side validation, the following line returns false
/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test( 'ó[email protected]' );
which apparently complies with this standard even though the demo for this exact code also fails.
EmailAddressAttribute
uses the following Regex to validate the value: source. The email address you provide matches the regex, so it should be valid. Can you post the c# model? By the way, I recently wrote a blog post about validating email address .NET – Basiliusjquery.validate.unobtrusive.js
library is loaded. I've added the input box HTML to the question – Hió
char can even be in an email address. Since it is non-ascii and everything. – Habitudea-zA-Z
which would appear to be a bug. – Royston