Click the "Download" button below to retrieve a copy of this tag,
including the complete documentation and sample usage shown
on this page. Place the downloaded ".inc" file in your
LassoStartup folder, restart Lasso, and you can begin using this
tag immediately.
define_tag(
'validHexColor',
-namespace='mp_',
-priority='replace',
-required='colorstring',
-description='Validates input string determining if it is a valid hex color (returns TRUE/FALSE). If first character is "#" then it is stripped.'
);
//Setup output local var
local('out' = boolean);
//If leading character is a "#", remove it
#colorstring->removeleading('#');
//thanks to Johan for the below Regex!
//Test string for length (only 3 or 6 characters are valid) and then each digit so that each one is in the valid range (0-9 or a-f)
#out = string_findregexp(#colorstring, -find='^[0-9a-f]{3}$', -ignorecase) -> size > 0 || string_findregexp(#colorstring, -find='^[0-9a-f]{6}$', -ignorecase) -> size > 0;
return(#out);
/define_tag;