How to validate email is effective

1302 단어 emailX++validateEmail
// Copyright (C), 2014, CEU Co., Ltd.
// USR Changed by 2014-09-25T10:13:20 Fandy Xie    
// Version       : 1.0
// Description   :           
// Return        :
static boolean validateEmail(str _email)
{
    str emailRegex = @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
    str email;
    List emailAddresses;
    ListEnumerator enum;
    System.Text.RegularExpressions.Regex regEx;
    System.Text.RegularExpressions.Match regMatch;
    InteropPermission permission = new InteropPermission(InteropKind::ClrInterop);

    boolean retVal;

    permission.assert();

    //BP Deviation documented
    regEx = new System.Text.RegularExpressions.Regex(emailRegex);

    // Split the email address string and validate each email address
    emailAddresses = SysEmailDistributor::splitEmail(_email);
    enum = emailAddresses.getEnumerator();
    while(enum.moveNext())
    {
        email = enum.current();

        if (email)
        {
            regMatch = regEx.Match(email);
            retVal = regMatch.get_Success();
        }
        else
            retVal = false;

        // If a single email address is invalid, the string is invalid
        if(!retVal)
            break;
    }

    return retVal;
}

좋은 웹페이지 즐겨찾기