// Set the value in the CODE field setCodeField(inCode); // Remove leading "#" if present if(startsWith(inCode, "#")){ inCode = cropText(inCode, 1, countText(inCode)); } // Add hexadecimal prefix inCode = "0x" + inCode; // Validate the string as hexadecimal if(isHex(inCode)){ ...