Pattern p = Pattern.compile("\\s*|\t|\r|\n"); Matcher m = p.matcher(param.getUserName()); param.setUserName(m.replaceAll(""));