Skip to content

Instantly share code, notes, and snippets.

@Vladimir-Urik
Created November 12, 2021 11:51
Show Gist options
  • Save Vladimir-Urik/008c63069af037ee7e229a9bac1e94ea to your computer and use it in GitHub Desktop.
Save Vladimir-Urik/008c63069af037ee7e229a9bac1e94ea to your computer and use it in GitHub Desktop.
package cz.pvpcraft.gggedr.stats.common.utils;
public class ValidatorUtils {
public static boolean isInteger(String s) {
try {
Integer.parseInt(s);
} catch (NumberFormatException e) {
return false;
}
return true;
}
public static boolean isDouble(String s) {
try {
Double.parseDouble(s);
} catch (NumberFormatException e) {
return false;
}
return true;
}
public static boolean isLong(String s) {
try {
Long.parseLong(s);
} catch (NumberFormatException e) {
return false;
}
return true;
}
public static boolean isFloat(String s) {
try {
Float.parseFloat(s);
} catch (NumberFormatException e) {
return false;
}
return true;
}
public static boolean isShort(String s) {
try {
Short.parseShort(s);
} catch (NumberFormatException e) {
return false;
}
return true;
}
public static boolean isByte(String s) {
try {
Byte.parseByte(s);
} catch (NumberFormatException e) {
return false;
}
return true;
}
public static boolean isBoolean(String s) {
return s.equalsIgnoreCase("true") || s.equalsIgnoreCase("false");
}
public static boolean isChar(String s) {
return s.length() == 1;
}
public static boolean isNick(String s) {
return s.length() > 2 && s.length() < 16;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment