valtype::luhn5(3tcl)
π valtype::luhn5 β the manual page, but make it make sense π
okay bestie, gather round, because this is the valtype::luhn5(3tcl) page from the Validation types corner of the tcllib universe, and honestly? it's giving "tiny package, huge responsibility." π
β¨ NAME β¨
valtype::luhn5 β Validation for plain number with a LUHN5 checkdigit
π SYNOPSIS π
package require Tcl 8.5 9
package require snit 2
package require valtype::common
package require valtype::luhn5 ?1.1?
valtype::luhn5 validate value
valtype::luhn5 checkdigit value
like. look at those requires. Tcl 8.5 9, snit 2, valtype::common, and then valtype::luhn5 ?1.1? β the little ?1.1? is optional and it's lowkey iconic of it. π
π¦ DESCRIPTION π¦
This package implements a snit validation type for a plain number with a LUHN5 checkdigit.
so what even is a validation type, you ask? bestie, it's an object that you use to check Tcl values of a particular kind. the classic example: snit::integer, a validation type that the snit package defines, and its whole job is making sure a Tcl value is actually an integer. simple. effective. queen behaviour. π
Every validation type has a validate method, and that's the one doing the actual validating. rules of the game:
- it takes a single argument, the value to be validated;
- if the value is valid, it does nothing;
- if the value is invalid, it throws an error.
fr fr:
valtype::luhn5 validate .... ;# Does nothing
valtype::luhn5 validate .... ;# Throws an error (bad luhn5 checkdigit).
The validate method will always return the validated value on success, and throw the -errorcode INVALID on error, possibly with additional elements which provide more details about the problem.
π API π
The API provided by this package satisfies the specification of snit validation types found in the documentation of Snit's Not Incr Tcl.
valtype::luhn5 validate valueβ This method validates the value and returns it, possibly in a canonical form, if it passes. If the value does not pass the validation an error is thrown. no notes. β¨valtype::luhn5 checkdigit valueβ This method computes a check digit for the value. Before doing so it is validated, except for a checkdigit. If the value does not pass the validation no check digit is calculated and an error is thrown instead. so it checks first, then does the math. she's methodical. π§
π ERROR CODES π
As said in the package description, the errors thrown by the commands of this package in response to input validation failures use the -errorcode INVALID to distinguish themselves from package internal errors.
and because INVALID alone is not enough tea to spill, the -errorCode goes actually beyond that. First, it will contain a code detailing the type itself. Here this is LUHN5. This is then followed by values detailing the reason for the failure. The full set of -errorCodes which can be thrown by this package are:
INVALID LUHN5 CHARACTERβ The input value contained one or more bad characters, i.e. characters which must not occur in the input for it to be a plain number with a LUHN5 checkdigit. bestie typed a letter. in a number. we're not okay. πINVALID LUHN5 CHECK-DIGITβ The check digit of the input value is wrong. This usually signals a data-entry error, with digits transposed, forgotten, etc. Of course, th input may be an outright fake too. (yes, that typo is literally in the original and i'm keeping it, that's the rules π«Ά)
ngl, that second one is the whole point of a checkdigit, and it's catching transposed digits, forgotten digits, and also just straight-up lies. she does it all.
πΈ BUGS, IDEAS, FEEDBACK πΈ
This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category valtype of the Tcllib Trackers at http://core.tcl.tk/tcllib/reportlist. Please also report any ideas for enhancements you may have for either package and/or documentation.
When proposing code changes, please provide unified diffs, i.e the output of diff -u.
Note further that attachments are strongly preferred over inlined patches. Attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar. (left-most button. remember it. that's the one. π)
π KEYWORDS π
Checking, Testing, Type checking, Validation, Value checking, isA, luhn, luhn-5
β CATEGORY β
Validation, Type checking
π«Ά COPYRIGHT π«Ά
Copyright (c) 2011 Andreas Kupries <andreas_kupries@users.sourceforge.net>
and that's the whole page, bestie π this lil slice of documentation ships with tcllib, version 1.1, and the page itself is valtype::luhn5(3tcl). go validate something. slay. β¨π¦π
π¦ where this page comes from
- debian trixie: tcllib 2.0+dfsg-4 Β· Tcl
- ubuntu questing: tcllib 2.0+dfsg-4
- ubuntu resolute: tcllib 2.0+dfsg-5 Β· Tcl
- ubuntu stonking: tcllib 2.0+dfsg-6 Β· Tcl
- Copyright (c) 2011 Andreas Kupries <andreas_kupries@users\&.sourceforge\&.net>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms