当前位置: 移动技术网 > IT编程>开发语言>c# > c#判断email地址是否为合法

c#判断email地址是否为合法

2019年07月18日  | 移动技术网IT编程  | 我要评论

题目要求:

关键代码如下所示:

class program
{
static void main(string[] args)
{
console.writeline("请输入正确的邮箱地址,以 @sina.com 结尾");
string us =convert.tostring(console.readline());
string str1 = us.replace("@", "");
int count = us.length - str1.length;
string str2 = us.replace(".", "");
int count2 = us.length - str2.length;
int count3 = us.length - 1;
int xl=us.indexof(".")-us.indexof("@");
bool mw = (us.indexof("@sina.com") == (us.length-9));
while (count == 1 && count2 == 1 && us.indexof("@") > 0 && us.indexof(".") > us.indexof("@") 
&& us.indexof(".")<count3)
{
if (xl != 1 && us.contains("@sina.com") && mw)
{
console.writeline("正确");
}
else {
console.writeline("输入的邮箱地址有误");
}
break;
}
console.readline();
}
}

以上所述是小编给大家介绍的c#判断email地址是否为合法,希望对大家有所帮助

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网