标签:
练习:判断邮箱格式是否正确
1.有且只能有一个@
2.不能以@开头
3.@之后至少有一个.
4.@和.不能靠在一起
5.不能以.结尾
1 Console.Write("请输入邮箱地址:"); 2 string m = Console.ReadLine(); 3 if (m.IndexOf("@") == m.LastIndexOf("@")) 4 { 5 if (m.IndexOf("@") != 0) 6 { 7 string a = m.Substring(m.IndexOf("@")); 8 bool b=a.Contains("."); 9 if (b == true) 10 { 11 if (a.IndexOf(".") != 1) 12 { 13 if (m.Length - 1 != m.LastIndexOf(".")) 14 { 15 Console.WriteLine("您输入的格式正确!"); 16 } 17 else 18 { 19 Console.WriteLine("您输入的格式有误!"); 20 } 21 } 22 else 23 { 24 Console.WriteLine("您输入的格式有误!"); 25 } 26 } 27 else 28 { 29 Console.WriteLine("您输入的格式有误!"); 30 } 31 } 32 else 33 { 34 35 Console.WriteLine("您输入的格式有误!"); 36 } 37 } 38 else 39 { 40 Console.WriteLine("您输入的格式有误!"); 41 } 42 43 Console.ReadLine();
标签:
原文地址:http://www.cnblogs.com/zk0533/p/5267392.html