[mp_validHexColor]

Description

Link: [mp_validHexColor]
Author: Marc Pinnell
Category: String
Version: 8.5.x
License: Public Domain
Posted: Mar. 02, 2010
Updated: Mar. 02, 2010
More by this author...
Validates input string determining if it is a valid hex color (returns TRUE/FALSE). If first character is "#" then it is stripped.

Parameters

-colorstring string, required string to test for validity

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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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

none

Email:


Password:



Newest

Most Popular

Support tagSwap.net