I'm using the EmailAddressAttribute for use on my model.
The problem is when I use a (perfectly valid) e-mail address of
óscar@yahoo.com
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( 'óscar@yahoo.com' );
which apparently complies with this standard even though the demo for this exact code also fails.
You need to set custom regular expression for email validation in jQuery Validation Plugin:
$.validator.methods.email = function( value, element ) {
return this.optional( element ) || /INSERT_YOUR_REGEX_HERE/.test( value );
}
jQuery Validation Plugin uses RFC 5322 Internet Message Protocol specification definition of a valid email. This definition disallows use of a non latin letters in local-part. Relevant excerpt from project's README.md:
IMPORTANT NOTE ABOUT EMAIL VALIDATION. As of version 1.12.0 this plugin is using the same regular expression that the HTML5 specification suggests for browsers to use. We will follow their lead and use the same check. If you think the specification is wrong, please report the issue to them. If you have different requirements, consider using a custom method. In case you need to adjust the built-in validation regular expression patterns, please follow the documentation.
Email address internationalization is defined by another specification - RFC 6530 Overview and Framework for Internationalized Email. It uses term SMTPUTF8. Check Email address page on Wikipedia for more information and support details.