[Note] Does your system have this bug? (Regular Expression verification)

Source: Internet
Author: User

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 );
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.