Given a string like #fff443
or #999999
How do I verify that the string has:
- 7 characters, with the first one being a hash
- no symbols in the string besides the hash in the beginning
Given a string like #fff443
or #999999
How do I verify that the string has:
- 7 characters, with the first one being a hash
- no symbols in the string besides the hash in the beginning
- 1 there are many ways to check with different structures : see my advanced answer : stackoverflow.com/questions/8027423/… – Royi Namir Commented Jan 15, 2012 at 10:05
1 Answer
Reset to default 23It seems that you are matching against a css color:
function isValidColor(str) {
return str.match(/^#[a-f0-9]{6}$/i) !== null;
}
To elaborate:
^
match beginning
#
a hash
[a-f0-9]
any letter from a-f and 0-9
{6}
the previous group appears exactly 6 times
$
match end
i
ignore case