Lasso Soft Inc. > Home

[mp_validHexColor]

Linkmp_validHexColor
AuthorMarc Pinnell
CategoryString
Version8.5.x
LicensePublic Domain
Posted02 Mar 2010
Updated02 Mar 2010
More by this author...

Description

Validates input string determining if it is a valid hex color (returns TRUE/FALSE). If first character is "#" then it is stripped.

Sample Usage

mp_validHexColor('aabbcc')

=> TRUE

mp_validHexColor('#123abce')

=> FALSE

mp_validHexColor('#aFaE3f')

=> TRUE

Source Code

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;

Comments

No comments

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft