Link | jina_checksum |
Author | Jolle Carlestam |
Category | Custom Tag |
Version | 8.5.x |
License | Public Domain |
Posted | 11 Mar 2009 |
Updated | 13 Mar 2009 |
More by this author... |
Tag using the Luhn algorithm, a simple checksum formula, to handle checksums for a given numerical value. It can either validate that a number ends with a correct checksum or add a checksum to a number. The Luhn algorithm is used for credit card numbers, different ID numbers like in Sweden or Canada etc.
jina_checksum('NNNNNNNN') will return true or false depending on if the checksum checks. Usage with optional param -add jina_checksum('NNNNNNNN', -add) returns the correct checksum for the checked value. var('checkme' = '4124 9720 0139 655'); jina_checksum($checkme, -add); -> 8
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('checksum', -namespace = 'jina_', -req = 'check', -copy, -opt = 'add' ); // tag used for the Luhn algorithm a simple checksum formula // used to validate a variety of identification numbers // usage jina_checksum('NNNNNNNN') // will return true or false depending on if the checksum checks // usage with optional param -add jina_checksum('NNNNNNNN', -add) // returns the correct checksum for the checked value local('temp', 'total' = integer, 'odd' ); #check = string_replaceregexp(#check, -find = '[^0-9]', -replace = ''); if(local_defined('add')); ((#check -> size % 2) == 1 ? #odd = true | #odd = false); else; ((#check -> size % 2) == 0 ? #odd = true | #odd = false); /if; loop(-from = #check -> size, -to = 1, -by = -1); if(#odd); #temp = integer(#check -> get(loop_count)) * ((loop_count % 2) + 1); else; #temp = integer(#check -> get(loop_count)) * (((loop_count + 1) % 2) + 1); /if; (#temp > 9 ? #temp -= 9); #total += #temp; /loop; if(local_defined('add')); return((#total % 10 == 0) ? 0 | ((#total + 10) - (#total % 10)) - #total); else(#total % 10 == 0); return(true); else; return(false); /if; /define_tag;
No comments
©LassoSoft Inc 2015 | Web Development by Treefrog Inc | Privacy | Legal terms and Shipping | Contact LassoSoft