1

We deal with many french clients and this is a problem on our sign up forms.

How can I tell the control to allow for french characters?

Ultimately, the regex is the default one supplied by Microsoft:

\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
Nasreddine
  • 36,610
  • 17
  • 75
  • 94
PercivalMcGullicuddy
  • 5,263
  • 9
  • 46
  • 65
  • Is `fiancée@marriage.fr` a valid email address? – Andre Calil Aug 29 '12 at 14:52
  • By creating a Regular expression that allows french characters. – driis Aug 29 '12 at 14:53
  • 1
    You presumably have a regular expression that is not doign what you want. You should probably share that regular expression so we can tell you what is wrong with it. Also you probably shouldn't be trying too hard to validate an email address since they can be very complicated things. In general I'd personally just look for things that say it is definitely not an e-mail address (eg no @) and after that just trust them to have entered it correctly. – Chris Aug 29 '12 at 14:53
  • @Kronprinz But it *should*? I mean, are `fiancee@marriage` and `fiancée@marriage` different email addresses? – Andre Calil Aug 29 '12 at 14:56
  • 1
    @AndreCalil I was sceptical also but according to this SO question they are valid: http://stackoverflow.com/questions/760150/can-an-email-address-contain-international-non-english-characters – David Hall Aug 29 '12 at 14:59
  • 1
    E-mail addresses could only contain such characters in the domain name. And even then it's probably rare for people to have an IDN there. In any case, `\w` contains every letter in every script and that includes `é` too, so your regex is probably not the one that is being used. – Joey Aug 29 '12 at 14:59
  • `fiancée@marriage.fr` is matched by the regex you've given (`\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*`) – Chris Aug 29 '12 at 14:59
  • fiancée@marriage.fr is not working for the expression on IE 11 – Tony Dong Apr 30 '19 at 22:43

4 Answers4

2

Well basically the result of the regex should not be different whether there are accents or not. (See Regex accent insensitive? for reference)

But besides - i was not aware, that accents are valid within emails.

Community
  • 1
  • 1
TGlatzer
  • 5,815
  • 2
  • 25
  • 46
1

Even if I can't make the regex provided by Microsoft work, if \w still doesn't match special characters as èéà you can replace any \w instance with [\wèéà] to make this regex accept any word literal and also any of the special chars you provide (maybe omit those special characters in the domain part, I think you'll never find some@test.còm)

Maybe it is not in the answer scope, but would you take some time to look at the answers to this question to get some ideas about email validation?

Community
  • 1
  • 1
Gabber
  • 5,152
  • 6
  • 35
  • 49
  • As I said on another answer "\w includes accented characters..." – Chris Aug 29 '12 at 15:12
  • @Chris i red and tested your answers as other ones before answering myself. If I didn't understand badly there are cases where \w (depending for example on CultureInfo) can not match characters with accents. May be mistaken though – Gabber Aug 29 '12 at 15:16
  • Ah, perhaps. In my testing it matched perfectly but you are right it might depend on your current culture. – Chris Aug 29 '12 at 15:18
  • http://social.msdn.microsoft.com/Forums/en-US/regexp/thread/af8b3af2-a43d-4627-a42f-516113de2cc9 ... my mistake, edited answer – Gabber Aug 29 '12 at 15:29
0

try this:

ValidationExpression="\w*[\éèà]+([-+.']\w+)*@\w*[\éèà]+([-.]\w+)*\.\w+([-.]\w+)*" />

Where [\éèà] are your special characters 'list'. You can also add /i ( [\éèà]/i ) to ignore case sensitive.

But I recommand to validate the email in the back-end:

public bool IsValidEmail(string email)
{
     bool isValidEmail = false;
     try
     {
         var validEmail = new MailAddress(email);
         isValidEmail = true;
     {
     catch (FormatException ex)
     {
         // The email has not a good format
     }
}
TrizZz
  • 1,200
  • 5
  • 15
  • 1
    Even if it didn't, one could just create an augmented character class that includes `\w` *and* the other characters instead of doing it this convoluted way. – Joey Aug 29 '12 at 15:03
  • 1
    @Chris It is actually not true... depending of your current culture info – TrizZz Aug 29 '12 at 15:17
  • @TrizZz: Yeah, I just had somebody else point that out to me. I still think it would be more sensible to just use the correct culture to check than make your regex more complicated. :) – Chris Aug 29 '12 at 15:20
  • What culture are you using out of interest? My tests had no specified culture and the only things I can find that mention regular expressions and culture suggest the culture is only relevant for case insensitive matching to determine what the equivalent upper nad lower case characters are... Its also a pain to test because regexes don't allow you to do anything explicit with teh culture... – Chris Aug 29 '12 at 15:31
  • I've done several tests now and using a en-GB or en-US culture will both match cyrillic characters so I am in fact pretty sure that \w will include accented characters no matter what culture you are using. I'd be interested to know what culture you are using that seems to make a difference or references that suggest my experimentation is incomplete. – Chris Aug 29 '12 at 15:46
  • Even compile does go through for the validation expression – Tony Dong Apr 30 '19 at 22:48
0

Try many ways above for the French email and all of those does not work for me and I find a solution is works for me.

ValidationExpression="[À-ÿ\w]+([-+.'][À-ÿ\w]+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
Tony Dong
  • 3,213
  • 1
  • 29
  • 32