Yeah, it heavily depends on the regex you are matching.
You should try to debug it first:
(I will be continuing with Sarfraz's code).
$(this).keyup(function () {
if(!regex.test(this.value))
this.style.backgroundColor=config.invalidColor;
$('#debug').html('invalid color');
else
this.style.backgroundColor=config.validColor;
$('#debug').html('valid color!');
});
Also, since you are using jQuery, you should rely more on its 'write less' philosophy.
$(this).keyup(function () {
if(!regex.test(this.value))
$(this).css('backgroundColor', config.invalidColor);
$('#debug').html('invalid color');
else
$(this).css('backgroundColor', config.validColor);
});
Maybe you should paste the regular expression code and what you are trying to achieve.