是否有电子邮件验证code

是否有电子邮件验证code

本文介绍了是否有电子邮件验证code Java ME的或BlackBerry?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有Java ME的或BlackBerry一些标准的电子邮件验证code样?


解决方案

 公共静态布尔validateEmailID(字符串email){
    电子邮件= email.trim();
    字符串反向=新的StringBuffer(电子邮件).reverse()的toString()。
    如果(电子邮件== NULL || email.length()== 0 || email.indexOf(@)== -1){
        返回false;
    }
    INT emailLength = email.length();
    INT atPosition = email.indexOf(@);
    INT atDot = reverse.indexOf(。);    串beforeAt = email.substring(0,atPosition);
    串afterAt = email.substring(atPosition + 1,emailLength);    如果(beforeAt.length()== 0 || afterAt.length()== 0){
        返回false;
    }
    的for(int i = 0; email.length() - 1 GT;我;我++){
        炭的i1 = email.charAt(ⅰ);
        炭I2 = email.charAt第(i + 1);
        如果(I1 ==&放大器'。';&放大器; i2的=='。'){
            返回false;
        }
    }
    如果(email.charAt(atPosition - ''''''1)== || email.charAt(0)== || email.charAt(atPosition + 1)== || afterAt.indexOf( !@)= -1 || atDot 2){
        返回false;
    }    返回true;
}

Is there some standard email validator code sample for Java ME or BlackBerry?

解决方案
public static boolean validateEmailID(String email) {
    email = email.trim();
    String reverse = new StringBuffer(email).reverse().toString();
    if (email == null || email.length() == 0 || email.indexOf("@") == -1) {
        return false;
    }
    int emailLength = email.length();
    int atPosition = email.indexOf("@");
    int atDot = reverse.indexOf(".");

    String beforeAt = email.substring(0, atPosition);
    String afterAt = email.substring(atPosition + 1, emailLength);

    if (beforeAt.length() == 0 || afterAt.length() == 0) {
        return false;
    }
    for (int i = 0; email.length() - 1 > i; i++) {
        char i1 = email.charAt(i);
        char i2 = email.charAt(i + 1);
        if (i1 == '.' && i2 == '.') {
            return false;
        }
    }
    if (email.charAt(atPosition - 1) == '.' || email.charAt(0) == '.' || email.charAt(atPosition + 1) == '.' || afterAt.indexOf("@") != -1 || atDot < 2) {
        return false;
    }

    return true;
}

这篇关于是否有电子邮件验证code Java ME的或BlackBerry?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 11:03