[原创] JAVA效验EMAIL

类别:Java 点击:0 评论:0 推荐:

   

  public static boolean isEmail ( String email){
        String emailChar = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.";
        String domainChar = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-";
        String domainExt = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
        String[] a,b;
        String aleft = "",aright = "";
        int indexPosition = -1;
        indexPosition = email.indexOf("@");
        if (indexPosition==-1) return false;
        if (indexPosition!=email.lastIndexOf("@")) return false;
        if (indexPosition==email.length()-1) return false;
        a = StringToStringArray(email,"@");
        aleft = a[0];
        if (!isInString(aleft,emailChar)) return false;
        aright = a[1];
        if (aright.indexOf(".")==-1) return false;
        if (aright.indexOf(".")==0) return false;
        if (aright.lastIndexOf(".")==aright.length()-1) return false;
        b = StringToStringArray(aright,".");
        for (int i=0;i<b.length;i++){
            if (!isInString(b[i],domainChar)) return false;
            if (i==b.length-1){
                if (!isInString(b[i],domainExt)) return false;
            }
        }
        return true;
    }

本文地址:http://com.8s8s.com/it/it9949.htm