-
package com.teamnavi.zstrade.common.util;
-
import java.util.regex.Matcher;
-
import java.util.regex. Pattern ;
-
/**
-
* 验证的公共方法
-
* @author pts
-
*
-
*/
-
public class VerificationUtils {
-
/**
-
*
-
* @param str 传入的 字符串
-
* @return 返回没有空格的字符串
-
*/
-
public static String removeSpaces(String str) {
-
if(null!=str){
-
String str2 = str.replaceAll(“\\s”, “”);
-
return str2;
-
}
-
return str;
-
}
-
/**
-
* 判断是否含有特殊字符
-
*
-
* @param str
-
* @return true为包含,false为不包含
-
*/
-
public static boolean isSpecialChar(String str) {
-
String regEx = “[ _`~!@#$%^&*()+=|{}’:;’,\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]|\n|\r|\t”;
-
Pattern p = Pattern.compile(regEx);
-
Matcher m = p.matcher(str);
-
return m.find();
-
}
-
}
文章来源:智云一二三科技
文章标题:分享两个公共方法 去除字符串全部空格,判断字符串是否有特殊字符
文章地址:https://www.zhihuclub.com/86264.shtml