kCompleteValidHexPattern top-level constant
String
const kCompleteValidHexPattern
RegExp pattern for validation complete HEX color String, allows only:
- exactly 6 or 8 digits in HEX format,
- only Latin A-F characters, case insensitive,
- and integer numbers 0,1,2,3,4,5,6,7,8,9,
- with optional hash (
#
) symbol at the beginning (not calculated in length).
final RegExp hexCompleteValidator = RegExp(kCompleteValidHexPattern);
if (hexCompleteValidator.hasMatch(hex)) print('$hex is valid HEX color');
Reference: https://en.wikipedia.org/wiki/Web_colors#Hex_triplet
Implementation
const String kCompleteValidHexPattern = r'^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$';