From 581451090ebc3e78b7439c06c9c3771032ce0540 Mon Sep 17 00:00:00 2001 From: Adam Conrad Date: Tue, 14 Jan 2020 13:25:25 -0500 Subject: [PATCH] Support CSS Colors Level 4 spec --- src/lib/isHexColor.js | 2 +- test/validators.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lib/isHexColor.js b/src/lib/isHexColor.js index 01f9d0e85..21a037504 100644 --- a/src/lib/isHexColor.js +++ b/src/lib/isHexColor.js @@ -1,6 +1,6 @@ import assertString from './util/assertString'; -const hexcolor = /^#?([0-9A-F]{3}|[0-9A-F]{6})$/i; +const hexcolor = /^#?([0-9A-F]{3}|[0-9A-F]{4}|[0-9A-F]{6}|[0-9A-F]{8})$/i; export default function isHexColor(str) { assertString(str); diff --git a/test/validators.js b/test/validators.js index c2f2a2fb9..cf3f09d10 100644 --- a/test/validators.js +++ b/test/validators.js @@ -2588,14 +2588,16 @@ describe('Validators', () => { test({ validator: 'isHexColor', valid: [ + '#ff0000ff', '#ff0034', '#CCCCCC', + '0f38', 'fff', '#f00', ], invalid: [ '#ff', - 'fff0', + 'fff0a', '#ff12FG', ], });