java正则表达式判断字符串是否仅含有数字和字母
import org.springframework.util.StringUtils;
/**
* @program: huawen-cloud-parent
* @ClassName: ValidateUtil
* @version: 1.0
* @description: 验证工具类
* @author: zhaonian
* @create: 2019-12-13 14:49
**/
public class ValidateUtil {
/** 全字母规则 正整数规则*/
public static final String STR_ENG_PATTERN="^[a-z0-9A-Z]+$";
/** 正整数规则 */
public static final String POSITIVE_INTEGER_PATTERN = "" ;
/**
* 判断字符串是否全字母 并且全部是正数数字
* @param str 字符串
* @return boolean
*/
public static boolean validateStrEnglish(final String str){
if(StringUtils.isEmpty(str)){
return Boolean.FALSE ;
}
if(StringUtils.isEmpty(str)){
return Boolean.FALSE ;
}
boolean matches = str.matches(STR_ENG_PATTERN);
if(str.length() < 6 || str.length() > 20) {
return Boolean.FALSE;
}
if (matches){
return Boolean.TRUE;
}else{
return Boolean.FALSE;
}
}
public static void main(String[] args) {
boolean b = validateStrEnglish("11111111..s1111");
System.out.println(b);
}
}