Algori...M11_013(3pm)

๐Ÿ“ฆ
version 1.3.6 ยท 5 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

๐Ÿ’– NAME ๐Ÿ’–

CheckDigits::M11_013 โ€” ok so bestie, this is the one that computes check digits for the VAT Registration Number (GR) โœจ๐Ÿ‡ฌ๐Ÿ‡ท


๐ŸŒธ SYNOPSIS ๐ŸŒธ

use Algorithm::CheckDigits;

$ustid = CheckDigits('ustid_gr');

if ($ustid->is_valid('123456783')) {
      # do something
}

$cn = $ustid->complete('12345678');
# $cn = '123456783'

$cd = $ustid->checkdigit('123456783');
# $cd = '3'

$bn = $ustid->basenumber('123456783');
# $bn = '12345678';

literally that's the whole vibe. build it, check it, split it back apart ๐Ÿซถ


๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

โœจ ALGORITHM โœจ

okay so here's the actual math, and ngl it's cute:

  1. Starting from the right, with the digit right before the checkdigit โ€” every digit gets weighted with 2 ** position. So the last digit times 2, the next one times 4, then 8, and so on forever ๐Ÿ’…
  2. Add all those weighted digits together, bestie. Just sum 'em. ๐Ÿงฎ
  3. Take that sum from step 2 and mod it by 11 โ€” modulo 11 icon behaviour.
  4. If the number you got in step 3 is greater than 9, then the check sum is 0 โ€” otherwise it's just that sum itself. periodt. โœจ

๐Ÿ’œ METHODS ๐Ÿ’œ

  • is_valid($number) โ€” gives you back true only if $number is made up of nothing but numbers, and the rightmost digit is a valid check digit per the algorithm above ๐Ÿ‘‘. Anything else? false, sorry babe, returns false otherwise ๐Ÿ™ˆ
  • complete($number) โ€” it computes the check digit for $number and appends it right onto the end ๐ŸŽ€. You get back the complete number with the check digit โ€” or '' if $number isn't solely digits ๐Ÿ’€
  • basenumber($number) โ€” hands you the basenumber of $number, but only if $number has a valid check digit โœ…. Otherwise it returns ''.
  • checkdigit($number) โ€” gives you the check digits of $number, again only if it has valid check digits. Otherwise it returns '' ๐Ÿ˜ญ

๐ŸŒˆ EXPORT ๐ŸŒˆ

None by default. like, zero. nothing. she stays private ๐Ÿ’…


โญ AUTHOR โญ

Mathias Weidner, "<mamawe@cpan.org>" ๐Ÿ‘‘ absolute legend, credit where credit is due fr fr.


๐ŸŽ€ SEE ALSO ๐ŸŽ€

  • perl
  • CheckDigits
  • www.pruefziffernberechnung.de,
  • (and honestly, go read those, they ate) โœจ

k bye bestie, go validate those numbers ๐Ÿ’–

this was perl v5.36.0, dated 2022-10-13, and it's the Algori...M11_013(3pm) page โ€” mwah, slay, drink water ๐Ÿ’…๐ŸŒธ

๐Ÿ“ฆ where this page comes from