Click here to Skip to main content
15,900,725 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to find the Host Name and Username from a given email address.
I'm writing a library/control set to upload if I can finish this task.
Here's an example of what I need to find:
Say we have my email: shelby.p67@gmail.com
The '@' symbol seperates the the user 'shelby.p67' from the host name 'gmail.com'.
Problem:
I'm building a class for a control and don't want to use System.Net.Mail.MailAddress class that the .Net framework provides. Third party libraries won't do because this is a matter of me just not knowing RegularExpressions aswell as I thought.
Posted

1 solution

I think this works, not 100% sure.
C#
public string Address
        {
            get
            {
                if (_user != null && _host != null)
                    return _user + "@" + _host;
                else
                    return _address;
            }
            set
            {
                _address = value;
                if (IsValidEmail(_address))
                {
                    int atIndex = _address.IndexOf('@');
                    _user = _address.ToString().Substring(0,atIndex);
                    _host = _address.ToString().Substring(atIndex, _address.Length - atIndex);
                }
                else
                    _user = _host = null;
            }
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900