+ Added hex verification

This commit is contained in:
Matthew Cech
2020-02-21 11:22:20 -08:00
parent a77725791a
commit 1a2366f5ee
+15 -1
View File
@@ -75,7 +75,21 @@ public class NetworkTheColorAPI
{ {
try try
{ {
hex = hex.replace("#", ""); hex = hex.replace("#", "").trim();
String hexUpper = hex.toUpperCase();
// Verify the number is hex.
for(int i = 0; i < hexUpper.length(); ++i)
{
char current = hexUpper.charAt(i);
Boolean isValidNum = current >= '0' && current <= '9';
Boolean isValidChar = current >= 'A' && current <= 'F';
// If it's not a valid character or a valid number, return null/
if(!isValidNum && !isValidChar)
return null;
}
String response = HTTPUtils.sendGETRequest("https://www.thecolorapi.com/id?hex=" + hex); String response = HTTPUtils.sendGETRequest("https://www.thecolorapi.com/id?hex=" + hex);
ColorData data = jsonParser.fromJson(response, ColorData.class); ColorData data = jsonParser.fromJson(response, ColorData.class);