1、正则表达式验证特殊符号
/** 正则表达式验证特殊字符及符号 进行编号的认证 */
public boolean isSpecialSymbols(String str_content) {
String regTitle = "[`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]";
Pattern p = Pattern.compile(regTitle);
Matcher m = p.matcher(str_content);
if (m.find()) {
return false;
} else {
return true;
}
}
2、正则表达式验证是否是正确的手机号或者座机号
/**
* 是否是正确的手机号或者座机
*
* @param phoneNumber
* @return
*/
public static boolean isPhoneNumberValid(String phoneNumber) {
boolean isValid = false;
String expression = "((^(\\d{2,4}[-_-—]?)?\\d{3,8}([-_-—]+\\d{3,8})?([-_-—]+\\d{1,7})?$)|(^0?1[35]\\d{9}$))";
CharSequence inputStr = phoneNumber;
Pattern pattern = Pattern.compile(expression);
Matcher matcher = pattern.matcher(inputStr);
if (matcher.matches()) {
isValid = true;
}
return isValid;
}
public static boolean isTelValid(String phoneNumber) {
boolean isValid = false;
// String
// expression="((^(\\d{2,4}[-_-—]?)?\\d{3,8}([-_-—]+\\d{3,8})?([-_-—]+\\d{1,7})?$)|(^0?1[35]\\d{9}$))";
String expression = "((^((0\\d{2,3})-)(\\d{7,8})(-(\\d{3,}))?$))";
CharSequence inputStr = phoneNumber;
Pattern pattern = Pattern.compile(expression);
Matcher matcher = pattern.matcher(inputStr);
if (matcher.matches()) {
isValid = true;
}
return isValid;
}