Link | mp_validHexColor |
Author | Marc Pinnell |
Category | String |
Version | 8.5.x |
License | Public Domain |
Posted | 02 Mar 2010 |
Updated | 02 Mar 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.
mp_validHexColor('aabbcc') => TRUE mp_validHexColor('#123abce') => FALSE mp_validHexColor('#aFaE3f') => TRUE
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;
No comments
©LassoSoft Inc 2015 | Web Development by Treefrog Inc | Privacy | Legal terms and Shipping | Contact LassoSoft