码迷,mamicode.com
首页 > 其他好文 > 详细

判断 邮箱格式是否正确

时间:2016-03-11 23:40:36      阅读:247      评论:0      收藏:0      [点我收藏+]

标签:

练习:判断邮箱格式是否正确
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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!