如何检查E-mail地址是否正确?

chrisz 2001-02-21 10:25:00
有哪位热心人帮我解决一下:检查E-mail地址和Internet地址是否正确的代码该怎么写?给我拎个头,或指点一下也可。小弟感激不尽!我最后的24分都给你了……
...全文
4308 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
月光 2001-02-22
  • 打赏
  • 举报
回复
不需要查得那么仔细吧,Email地址要包含'@','.'等。
mycode 2001-02-22
  • 打赏
  • 举报
回复
以上的检查只是对形式的检查,要从根本上解决问题,应该去查询该域名是否存在.tcpip协议中的whois协议可以查询国际域名,其他域名是否支持还不支道.
laza 2001-02-21
  • 打赏
  • 举报
回复
检查email是否合法。
function IsValidEmail(const Value: string): boolean;
function CheckAllowed(const s: string): boolean;
var
i: integer;
begin
Result:= false;
for i:= 1 to Length(s) do
begin
// illegal char in s -> no valid address
if not (s[i] in ['a'..'z','A'..'Z','0'..'9','_','-','.']) then
Exit;
end;
Result:= true;
end;
var
i: integer;
namePart, serverPart: string;
begin // of IsValidEmail
Result:= false;
i:= Pos('@', Value);
if (i = 0) or (pos('..', Value) > 0) then
Exit;
namePart:= Copy(Value, 1, i - 1);
serverPart:= Copy(Value, i + 1, Length(Value));
if (Length(namePart) = 0) // @ or name missing
or ((Length(serverPart) < 4)) // name or server missing or
then Exit; // too short
i:= Pos('.', serverPart);
// must have dot and at least 3 places from end
if (i = 0) or (i >= (Length(serverPart) - 2)) then
Exit;
Result:= CheckAllowed(namePart) and CheckAllowed(serverPart);
end;
调用例子:
var
EmailName: string;
begin
EmailName := InputBox('输入你的E-Mail', 'E-Mail:', '');
if IsValidEmail(EmailName) then showmessage('Good!')
else showmessage('Worse');
end;
internet地址判断,ip地址搜索一下又讨论。

其实你可以自己写判断 dot位置问题。搜索一下,“判断字符串是否为数字"。

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧