Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
How do you make sure there are at least two characters between the @ character abd the . character.
Posted 8-Nov-12 12:59pm
Comments
Nelek at 8-Nov-12 19:24pm
   
Please don't repost questions. With one time is enough.
c# email validation with if statement[^]
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

public static bool IsValidEmail(string strEmail)
        {
            bool result = true;
 
            if (strEmail.Length < 8)
            {
                result = false;
            }
            else if (!strEmail.Contains("@"))
            {
                result = false;
            }
            else if (strEmail.IndexOf("@") < 2)
            {
                result = false;
            }
            else if (!strEmail.Contains("."))
            {
                result = false;
            }
            else if (strEmail.IndexOf(".") < 6)
            {
                result = false;
            }
             else if (strEmail.IndexOf("."))
            {
                result = false;
            }
            else
            {
                result = true;
            }
 
            return result;
        }
    }
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

public static bool IsValidEmail(string email)
        {
            string[] sArray=email.Split('@');
            string emailsplit=sArray[1];
            string[] lastArray=emailsplit.Split('.');
 
            return lastArray[0].Length > 2;
        }
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 6,696
1 Sergey Alexandrovich Kryukov 6,675
2 CPallini 5,315
3 George Jonsson 3,584
4 Gihan Liyanage 2,650


Advertise | Privacy | Mobile
Web04 | 2.8.140921.1 | Last Updated 8 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100