Last active
March 23, 2023 17:22
-
-
Save safareli/10603775 to your computer and use it in GitHub Desktop.
ported from java version http://stackoverflow.com/a/12457269/1798418
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var keywords_color_regex = /^[a-z]*$/; | |
var hex_color_regex = /^#[0-9a-f]{3}([0-9a-f]{3})?$/; | |
var rgb_color_regex = /^rgb\(\s*(0|[1-9]\d?|1\d\d?|2[0-4]\d|25[0-5])%?\s*,\s*(0|[1-9]\d?|1\d\d?|2[0-4]\d|25[0-5])%?\s*,\s*(0|[1-9]\d?|1\d\d?|2[0-4]\d|25[0-5])%?\s*\)$/; | |
var rgba_color_regex = /^rgba\(\s*(0|[1-9]\d?|1\d\d?|2[0-4]\d|25[0-5])%?\s*,\s*(0|[1-9]\d?|1\d\d?|2[0-4]\d|25[0-5])%?\s*,\s*(0|[1-9]\d?|1\d\d?|2[0-4]\d|25[0-5])%?\s*,\s*((0.[1-9])|[01])\s*\)$/; | |
var hsl_color_regex = /^hsl\(\s*(0|[1-9]\d?|[12]\d\d|3[0-5]\d)\s*,\s*((0|[1-9]\d?|100)%)\s*,\s*((0|[1-9]\d?|100)%)\s*\)$/; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In CSS RGB/RGBA can contain
%
values (all values in %) like: rgb(20%, 50%, 90%). In such case the example will return false and fail.