During the email sending test today, I found that some mailboxes always report exceptions. After careful check, these abnormal mailboxes all contain Chinese and full-angle letters. After some checks, the method for verifying the email format cannot distinguish the email addresses that contain Chinese characters. The regular expression in this verification method is the same as that in the aspx web page, while the mailbox verification in the web page is okay. Why is this C # Write method just passable?
After repeated tests, we found that the regexoptions. ecmascript option must be added to the regular expression verification to differentiate Chinese characters. The validation on the ASP. NET web page is actually Javascript Regular Expression verification, so it can be judged normally. The server verification is easy to ignore because the client is normal during testing.
It is estimated that many of my friends have this bug in their systems. I just tested several websites that have such a problem, including this problem in the blog Park, dudu should pay attention to it (as long as the client script is disabled, it can be successfully registered with a mailbox containing Chinese characters when registering a user. Of course, it is not only mailbox verification, but also other problems related to regular expression verification may exist)
The Code is as follows:
Code
// Unable to judge: Chinese @ domain.com
Public bool isemail (string Str)
{
If (STR = NULL | Str. Trim (). Length = 0)
Return false;
Return RegEx. ismatch (Str. trim (), @ "^ \ W + ([-+. '] \ W +) * @ \ W + ([-.] \ W + )*\. \ W + ([-.] \ W +) * $ ");
}
// Correct statement
Public bool isemail (string Str)
{
If (STR = NULL | Str. Trim (). Length = 0)
Return false;
Return RegEx. ismatch (Str. trim (), @ "^ \ W + ([-+. '] \ W +) * @ \ W + ([-.] \ W + )*\. \ W + ([-.] \ W +) * $ ", regexoptions. ecmascript );
}