日期:2014-05-20 浏览次数:20803 次
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args)throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.println("请输入要验证的邮箱地址:"+"\n"+"-->");
String inputStr = reader.readLine();
Main ma=new Main();
boolean x=ma.validateEmail(inputStr);
if(x==true){
System.out.println("1");
}else{
System.out.println("0");
}
}
public boolean validateEmail(String email) {
int pos = email.indexOf("@");
if (pos == -1 || pos == 0 || pos == email.length() - 1) {
return false;
}
String[] strings = email.split("@");
if (strings.length != 2) {
return false;
}
CharSequence cs = strings[0];
for (int i = 0; i < cs.length(); i++) {
char c = cs.charAt(i);
if(c==48){
return false;
}
if (!Character.isLetter(c) && !Character.isDigit(c)&& c!=95&& c!=46) {
return false;
}
}
pos = strings[1].indexOf(".");
if (pos == -1 || pos == 0 || pos == email.length() - 1) {
return false;
}
strings = strings[1].split("\\.");
if(strings.length<2){
return false;
}
for (int j = 0; j < strings.length; j++) {
cs = strings[j];
if(j==strings.length-1){
if(!cs.equals("com")){
return false;
};
}
if (cs.length() == 0) {
return false;
}
for (int i = 0; i < cs.length(); i++) {
char c = cs.charAt(i);
if(c==48){
return false;
}
if (!Character.isLetter(c) && !Character.isDigit(c) && c!=95) {
return false;
}
}
}
return true;
}
}
public boolean isEmail(String str){
Pattern pattern = Pattern.compile("^w+[-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*$”");
Matcher isNum = pattern.matcher(str);
if( !isNum.matches() ){
return false;
}
return true;
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args)throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.println("请输入要验证的邮箱地址:"+"\n"+"-->");
String inputStr = reader.readLine();
Main ma=new Main();
boolean x=ma.validateEmail(inputStr);
if(x==true){
System.out.println("1");
}else{
System.out.println("0");
}
}
public boolean validateEmail(String email) {
return Pattern.matches("^([A-Za-z1-9
------解决方案--------------------
.
------解决方案--------------------
_])+\\@([A-Za-z1-9
------解决方案--------------------
.
------解决方案--------------------
_])+[.com]+$", email);
}
}