Algori...M23_001(3pm)

πŸ“¦
version 1.3.6 Β· 5 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– NAME πŸ’–

CheckDigits::M23_001 β€” bestie, this is the module that computes check digits for DNI (ES). That's the Spanish national ID number situation, and yes it's iconic.

So real quick, the manual name is Algori...M23_001(3pm) from the User Contributed Perl Documentation, but like... the actual module is CheckDigits::M23_001. Same girl, shorter name. πŸŽ€


✨ SYNOPSIS ✨

Okay so this is literally how you use it, no cap:

use Algorithm::CheckDigits;

$dni = CheckDigits('dni_es');

if ($dni->is_valid('54362315K')) {
      # do something
}

$cn = $dni->complete('54362315');
# $cn = '54362315K'

$cd = $dni->checkdigit('54362315K');
# $cd = 'K'

$bn = $dni->basenumber('54362315K');
# $bn = '54362315'

Look at that. Four little calls and you're done. We love a low-effort slay. πŸ’…


🌸 DESCRIPTION 🌸

🧚 ALGORITHM 🧚

  1. The checkdigit is the whole number taken modulo 23 and coded according to a keytable.

That's it. That's the algorithm. Modulo 23 and a keytable, periodt. πŸ’€


πŸ‘‘ METHODS πŸ‘‘

  • is_valid($number) β€” Returns true only if $number consists solely of numbers and the last digit is a valid check digit according to the algorithm given above.

Returns false otherwise,

  • complete($number) β€” The check digit for $number is computed and concatenated to the end of $number.

Returns the complete number with check digit or '' if $number does not consist solely of digits and spaces.

  • basenumber($number) β€” Returns the basenumber of $number if $number has a valid check digit.

Return '' otherwise.

  • checkdigit($number) β€” Returns the checkdigit of $number if $number has a valid check digit.

Return '' otherwise.


πŸ¦‹ EXPORT πŸ¦‹

None by default. Not a single thing gets exported unless you ask, and honestly? Boundaries. 🫢


🌈 AUTHOR 🌈

Mathias Weidner, "<mamawe@cpan.org>" β€” thank you for your service, king. πŸ‘‘


⭐ SEE ALSO ⭐

  • perl
  • CheckDigits
  • www.pruefziffernberechnung.de

Heads up bestie: those method descriptions say exactly what they say β€” is_valid talks about digits, and complete shrugs and mentions digits and spaces. That's straight from the source, so don't come for me. 😭

Okay that's the whole page!! This was documented in perl v5.36.0, dated 2022-10-13, and it lives under the User Contributed Perl Documentation for Algori...M23_001(3pm). Byeee, go validate some DNIs, you ate. πŸ’–βœ¨πŸ¦‹

πŸ“¦ where this page comes from