用户信息简单验证
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public static boolean isMobile(String str) {
Pattern p = null;
Matcher m = null;
boolean b = false;
p = Pattern.compile("^[1][3,4,5,8][0-9]{9}$"); // 验证手机号
m = p.matcher(str);
b = m.matches();
return b;
}
public static boolean isPwd(String str) {
Pattern p = null;
Matcher m = null;
boolean b = false;
p = Pattern.compile("[a-zA-Z0-9]{6}$"); // 密码
m = p.matcher(str);
b = m.matches();
return b;
}
public static boolean isEmail(String str) {
Pattern p = null;
Matcher m = null;
boolean b = false;
p = Pattern.compile("^\\s*\\w+(?:\\.{0,1}[\\w-]+)*@[a-zA-Z0-9]+(?:[-.][a-zA-Z0-9]+)*\\.[a-zA-Z]+\\s*$"); // 验证邮箱
m = p.matcher(str);
b = m.matches();
return b;
}
public static boolean isPhone(String str) {
Pattern p1 = null,p2 = null;
Matcher m = null;
boolean b = false;
//p1 = Pattern.compile("^[0][1-9]{2,3}-[0-9]{5,10}$"); // 验证带区号的
p1 = Pattern.compile("^[0][0-9]{2,3}-[0-9]{5,10}$"); // 验证带区号的
p2 = Pattern.compile("^[1-9]{1}[0-9]{5,8}$"); // 验证没有区号的
//if(str.length() >9)
if(str.contains("-")){
m = p1.matcher(str);
b = m.matches();
}else{
m = p2.matcher(str);
b = m.matches();
}
return b;
}