Quick Regex Reference

Commonly Used:

 private bool ValidTLD(string tld)
        string[] validtlds = {"com","org","net","edu","gov","mil","biz","info","mobi","name","aero","asia","jobs","museum"};
        if (validtlds.Contains(tld.ToLower().Replace(".",""))) {
            return true;

        return false;

if (!ValidTLD(System.Text.RegularExpressions.Regex.Match(tbNewEmailAddress.Text, @"^\w+([-+.']\w+)*@.*(\.\w+)$").Groups[2].Value))
            hlnkReturn.Visible = false;
            tblSuccess.Visible = false;
            tblError.Visible = true;
            pnlMessages.Visible = true;
            lblErrorMessage.Visible = true;
            lblErrorMessage.Text = "Invalid domain specified. Please contact support if you continue to receive this message.";   

Get Top Level Domain of Email:

//ex. for ronniediaz@ronniediaz.com or ronniediaz@test.ronniediaz.com returns ".com"
string regextld = @"^\w+([-+.']\w+)*@.*(\.\w+)$";
if (System.Text.RegularExpressions.Regex.IsMatch(tbNewEmailAddress.Text, regextld))
            System.Text.RegularExpressions.Match m = System.Text.RegularExpressions.Regex.Match(tbNewEmailAddress.Text, regextld);
                return m.Groups[2].Value;

About Ronnie Diaz

Ronnie Diaz is an enterprise software engineer responsible for front-end and back-end development for companies in many industries. Heavily involved in cloud development, online retail, e-commerce and electronic ordering, fulfillment and customer relational systems.

Posted on April 1, 2011, in Programming & Development and tagged , , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: