import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegUtil {
/**
* 验证手机号码是否正确
* @param mobile
* @return
*/
public static boolean validatePhoneNumber(String mobile) {
Pattern p = Pattern.compile("^((13[0-9])|(12[0-9])|(19[0-9])|(16[0-9])|(14[0-9])|(15[0-9])|(17[0-9])|(18[0-9]))\\d{8}$");
Matcher m = p.matcher(mobile);
return m.matches();
}
/**
*验证是否是中文
* @param str
* @return
*/
public static boolean isChineseChar(String str) {
boolean temp = false;
Pattern p = Pattern.compile("[\u4e00-\u9fa5]");
Matcher m = p.matcher(str);
if (m.find()) {
temp = true;
}
return temp;
}
/**
*验证是否是数字
* @param str
* @return
*/
public static boolean isNumeric(String str) {
Pattern pattern = Pattern.compile("[0-9]*");
Matcher isNum = pattern.matcher(str);
if (!isNum.matches()) {
return false;
}
return true;
}
/**
* 是否十进制
* @param str
* @return
*/
public static boolean isDecimal(String str) {
str = str.replaceAll("\\.", "");
Pattern pattern2 = Pattern.compile("\\d+\\.\\d+$|-\\d+\\.\\d+$");
Matcher isMather = pattern2.matcher(str);
if (!isMather.matches()) {
return false;
}
return true;
}
/**
* 验证是否是英语
* @param word
* @return
*/
public static boolean isEnglish(String word) {
boolean sign = true;
for (int i = 0; i < word.length(); i++) {
if (!(word.charAt(i) >= 'A' && word.charAt(i) <= 'Z')
&& !(word.charAt(i) >= 'a' && word.charAt(i) <= 'z')) {
return false;
}
}
return true;
}
/**
*
* @param str
* @return
*/
public static boolean repaceIsNumeric(String str) {
String temp = str.replaceAll("-", "");
boolean flag = isNumeric(temp);
if (!flag) {
temp = str.replaceAll("\\.", "");
temp = temp.replaceAll("-", "");
temp = temp.replaceAll("\\+", "");
flag = isNumeric(temp);
return flag;
}
return true;
}
/**
* 是否是邮箱
* @param email
* @return
*/
public static boolean isEmail(String email) {
if (null == email || "".equals(email)) {
return false;
}
Pattern p = Pattern.compile("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");// 复杂匹配
Matcher m = p.matcher(email);
return m.matches();
}
/**
* 得到数字
* @param str
* @return
*/
public static String getNumberStr(String str){
String regEx="[^0-9]";
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(str);
String value = m.replaceAll("").trim();
return value;
}
public static void main(String[] args) {
System.out.println(RegUtil.repaceIsNumeric("15+"));
System.out.println("15+".replaceAll("15+", ""));
}
}