Checks if string is a valid email address format - CSharp System

CSharp examples for System:String Parse

Description

Checks if string is a valid email address format

Demo Code


using System.Text.RegularExpressions;
using System.Text;
using System.Globalization;
using System.Collections.Generic;
using System;//from w w  w  .jav  a2s  .  c o  m

public class Main{
        //Checks if string is a valid email address format
        //name@place.com -> True
        //hahaimfaking -> False
        //(Function works assuming the last part is no bigger than 3 letters (com, net, org))
        public static bool IsEmailAddress(string input)
        {
            if (input.IndexOf('@') != -1)
            {
                int indexOfDot = input.LastIndexOf('.');
                if (input.Length - indexOfDot > 0 && input.Length - indexOfDot <= 4)
                    return true;
            }
            return false;
        }
}

Related Tutorials