import javax.swing.JOptionPane;public class ETest
{
    public static void main(String[] args)
    {
        String mail=JOptionPane.showInputDialog(null, 
                              "Please Enter your Email address:");
        
        int index1=mail.indexOf('@');  
        String postfix=mail.substring(index1+1);
        int index2=postfix.indexOf(".com");
        int index3=postfix.indexOf(".net");
        
        
        if(!Character.isLetter(mail.charAt(0))
                                 ||index1<0||index2<0||index3<0)
        {
            JOptionPane.showMessageDialog(null,
                              "Your Email address is not valid!",
                              "Wrong Email",
                              JOptionPane.INFORMATION_MESSAGE);
        }
        else
        {
            JOptionPane.showMessageDialog(null,
                              "Your Email address is valid!","OK",
                              JOptionPane.INFORMATION_MESSAGE);
        }
   }
}

解决方案 »

  1.   

    有的网站的Email允许使用下画线,有的则禁止, 所以我没有对此判断。
      我忘了在程序的最后最后加上“System.exit(0);”了,请原谅
      

  2.   

    to : huqingmiao(小满)
    小满,现在越来越牛b了啊,工作怎么样啊,比较爽吧
      

  3.   

    TO: bobfallen 哦靠, 没想到在这碰到你, 我都激动得快流泪了。我好久没来CSDN了,你在北真牛