android 判断登录是否邮箱或手机号

来源:互联网 发布:软件项目计划书 编辑:程序博客网 时间:2024/05/01 03:23
/**
* 验证邮箱输入是否合法

* @param strEmail
* @return
*/
public static boolean isEmail(String strEmail) {
// String strPattern =
// "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
String strPattern = "^\\s*\\w+(?:\\.{0,1}[\\w-]+)*@[a-zA-Z0-9]+(?:[-.][a-zA-Z0-9]+)*\\.[a-zA-Z]+\\s*$";


Pattern p = Pattern.compile(strPattern);
Matcher m = p.matcher(strEmail);
return m.matches();
}

/**
* 验证是否是手机号码

* @param str
* @return
*/
public static boolean isMobile(String str) {
Pattern pattern = Pattern.compile("1[0-9]{10}");
Matcher matcher = pattern.matcher(str);
if (matcher.matches()) {
return true;
} else {
return false;
}

}

这段就是验证的直接封装好,以后可以直接调用

0 0