Java tutorial
//package com.java2s; //License from project: Open Source License public class Main { private static boolean isShortColorCode(String colorString) { return colorString.length() == 4 && colorString.startsWith("#") && isHexadecimalColor(colorString); } private static boolean isHexadecimalColor(String colorString) { try { Long.parseLong(colorString.substring(1), 16); return true; } catch (NumberFormatException e) { return false; } } }