isHexString function

bool isHexString(
  1. String value, {
  2. int length = 0,
})

Is the string a hex string.

Implementation

bool isHexString(String value, {int length = 0}) {
  if (!RegExp('^0x[0-9A-Fa-f]*\$').hasMatch(value)) {
    return false;
  }

  if (length > 0 && value.length != 2 + 2 * length) {
    return false;
  }

  return true;
}