电子邮件为字符串型 谢谢大家!!!

解决方案 »

  1.   

    关键就是看是否包含了@并且后面还要有XX.com XX.net 等等标志
      

  2.   

    试试我这个//检查邮件地址是否正确
    function IsEMail(EMail: string): Boolean;
    const IdChar = 'abcdefghijklmnopqrstuvwxyz1234567890_-.';
    var
      Tm, S: string;
      i, iPos: Integer;
    begin
      result := False;
      EMail := LowerCase(EMail);
      iPos := Pos('@', EMail);
      if iPos > 1 then
      begin
        Tm := Copy(EMail, 1, iPos - 1);
        if Copy(Tm, 1, 1) = '-' then Exit;
        if Copy(Tm, 1, 1) = '_' then Exit;
        if Copy(Tm, Length(Tm) - 1, 1) = '-' then Exit;
        if Copy(Tm, Length(Tm) - 1, 1) = '_' then Exit;
        for i := 1 to Length(Tm) do
          if (Pos(Copy(EMail, i, 1), Copy(IdChar, 1, Length(IdChar) - 1)) <= 0) then Exit;
        S := Copy(EMail, iPos + 1, Length(EMail) - iPos);
        i := Pos('.', S);
        if ((i > 1) and (Copy(S, iPos + 1, 1) <> '.') and (Copy(S, i + 1, Length(S)) <> '')) then
        begin
          if Copy(S, 1, 1) = '-' then Exit;
          if Copy(S, 1, 1) = '_' then Exit;
          if Copy(S, Length(S) - 1, 1) = '-' then Exit;
          if Copy(S, Length(S) - 1, 1) = '_' then Exit;
          for i := 1 to Length(S) do
            if Pos(Copy(S, i, 1), IdChar) <= 0 then Exit;
          result := true;
        end;
      end;
    end;
      

  3.   

    \b[\w-]+(\.[\w-]+)*@([\w-]+\.)+[0-9A-Za-z]{2,4}\b
    应该差不多是这个样子吧
      

  4.   

    在线检查邮件合法性,请使用TIdDNSResolver,保证可以完全检查。
      

  5.   

    To:laihongbo524(风铃夜思雨) 
    感谢你提供的这个函数 想的已经挺周到了
    但是好像电子邮件的用户名部分不能以数字开头呀:)