public static String trim(String str) {
if (str != null && !str.isEmpty()) {
String rs = str.trim();
rs = rs.replaceAll("\\s+", " ");
return rs;
}
return "";
}
Check string is null or empty.
public static boolean isNulOrEmpty(String value) {
return value == null || value.trim().isEmpty();
}
Check string is positive number.
public static boolean isPositiveNumber(String value) {
if (value != null) {
value = value.replaceAll("\\s+", "");
if (!value.isEmpty()) {
if (value.matches("^[0-9]+$")) {
return isNumber(value) && (toBigDecimal(value).longValue() > 0L);
}
}
}
return true;
}
//---------------------
Check Time (HH:MM): isValidWithPattern(tmpBis, "([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]");
Check Time (HH:MM:SS): isValidWithPattern(tmpBis, "([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]");
Check validate email address with regular expression.
public static boolean isValidEmailAddress(String email) {
if (email != null) {
email = email.replaceAll("\\s+", "");
if (!email.isEmpty()) {
String ePattern = "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$";
java.util.regex.Pattern p = java.util.regex.Pattern.compile(ePattern);
java.util.regex.Matcher m = p.matcher(email);
return m.matches();
}
}
return true;
}
Check validate string with regular expression.
public static boolean isValidWithPattern(String value, String pattern) {
if (value != null) {
if (!value.isEmpty()) {
java.util.regex.Pattern p = java.util.regex.Pattern.compile(pattern);
java.util.regex.Matcher m = p.matcher(value);
return m.matches();
}
}
return true;
}
--------------------
--------------------
0 comments:
Post a Comment