boolean (@Nullable CharSequence text) { if (text == null) { return false; } final int length = text.length(); if (length < 3) { return true; } boolean hex = true; final char firstChar = text.charAt(0); if (firstChar != '0') { if (!StringUtil.isDecimalDigit(firstChar)) { return true; } hex = false; } final char secondChar = text.charAt(1); if (hex && secondChar != 'x' && secondChar != 'X') { hex = false; } int index = hex ? 2 : 1; char nextChar = text.charAt(index); if (hex) { if (!StringUtil.isHexDigit(nextChar)) { return true; } } while (hex && StringUtil.isHexDigit(nextChar) || StringUtil.isDecimalDigit(nextChar) || nextChar == '_') { index++; if (index >= length) { return true; } nextChar = text.charAt(index); } if (nextChar != '.') { return true; } index++; if (index >= length) { return true; } nextChar = text.charAt(index); if (hex) { if (!StringUtil.isHexDigit(nextChar)) { return true; } } else if (!StringUtil.isDecimalDigit(nextChar)) { return true; } // <digit(s)><point><digit> seen, skip the rest. return false; }