C++/CLI Code Snippet - Validate Email Address

C++/CLI Code Snippet - Validate Email Address

C++/CLI Code Snippet - Validate Email Address

C++/CLI code snippet to validate given email address. IsValidEmail function validate email address. Function return TRUE if valid email address found, if not function will return FALSE.

Bookmark:

C++/CLI Code Snippet - Validate Email Address

This C++/CLI code snippet validate given email address. This function uses regular expression to match string pattern to validate email address.

bool IsValidEmail(System::String ^Email)
{
    System::String ^strRegex = "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}" + "\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\" + ".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
    System::Text::RegularExpressions::Regex ^_Regex = gcnew System::Text::RegularExpressions::Regex(strRegex);
    if (_Regex->IsMatch(Email))
        return (true);
    else
        return (false);
}


C++/CLI Keywords Used:

  • Regex
  • IsMatch

Code Snippet Information:

  • Applies To: .Net, C++/CLI, Email Validation, Regular Expression
  • Programming Language : C++/CLI

External Resources:

Leave a comment