会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
随机博客
Random Blog
博客园
首页
联系
订阅
管理
今天写了个检测邮件格式的算法~~
public
class
Check
{
public
static
bool
CheckEmail(
string
EmailString)
{
bool
Result
=
false
;
if
(EmailString.Length
>=
3
)
{
bool
atString
=
false
;
bool
dotString
=
false
;
int
atPosition
=
0
,atCount
=
0
;
int
dotPosition
=
0
;
string
Postfix;
Postfix
=
EmailString.Substring(EmailString.Length
-
3
,
3
);
Result
=
PostfixCheck(Postfix);
for
(
int
i
=
0
;i
<
EmailString.Length;i
++
)
{
if
(EmailString.Substring(i,
1
)
==
"
@
"
)
{
atString
=
true
;
atCount
+=
1
;
atPosition
=
i;
}
if
(EmailString.Substring(i,
1
)
==
"
.
"
)
{
dotString
=
true
;
dotPosition
=
i;
}
}
if
(atString
&&
dotString
&&
atCount
==
1
&&
System.Math.Abs(atPosition
-
dotPosition)
>
1
&&
Result)
Result
=
true
;
else
Result
=
false
;
}
else
Result
=
false
;
return
Result;
}
private
static
bool
PostfixCheck(
string
PostfixString)
{
bool
PostfixResult
=
false
;
string
PostfixTableString
=
"
com|net|org|cn |jp |gov|edu|int|mil|biz|cc |tv |ac |au |de |fr |hk |tw |uk |us |
"
;
//
要添加的后缀
for
(
int
i
=
0
;i
<
PostfixTableString.Length;i
+=
4
)
{
if
(PostfixString.ToUpper()
==
PostfixTableString.Substring(i,
3
).Trim().ToUpper()
||
PostfixString.Substring(
1
,
2
).ToUpper()
==
PostfixTableString.Substring(i,
3
).Trim().ToUpper())
{
PostfixResult
=
true
;
break
;
}
}
return
PostfixResult;
}
}
posted @
2006-05-15 17:35
随机
阅读(
479
) 评论(
2
)
收藏
举报
刷新页面
返回顶部
公告