def validate_hex(form, field):
data = field.data
error = ValidationError('%r is not a valid hex color')
# Strip a leading # for the hex number
if data.startswith('#'):
data = data[1:]
if len(data) not in (3, 6):
raise error
if any(c not in string.hexdigits for c in data):
raise error
评论列表
文章目录