valtype::luhn(3tcl)
π valtype::luhn β the manual, but make it make sense π
okay bestie, so this is the page for valtype::luhn from the Tcllib validation types crew (that's the 3tcl manual section, if you were wondering). grab a boba, we're doing check digits πΈ
β¨ NAME β¨
valtype::luhn β Validation for plain number with a LUHN checkdigit
π«Ά SYNOPSIS π«Ά
package require Tcl 8.5 9
package require snit 2
package require valtype::common
package require valtype::luhn ?1.1?
valtype::luhn validate value
valtype::luhn checkdigit value
π DESCRIPTION π
So this package implements a snit validation type for a plain number with a LUHN checkdigit. that's it, that's the whole job π
A validation type is an object you can use to validate Tcl values of a particular kind. Like, for example, snit::integer β a validation type defined by the snit package β is used to validate that a Tcl value is an integer. same energy, different digit situation.
Every validation type has a validate method, and that's the method doing the actual validating. Rules:
- it must take a single argument β the value to be validated
- further, it must do nothing if the value is valid
- but it must throw an error if the value is invalid
valtype::luhn validate .... ;# Does nothing
valtype::luhn validate .... ;# Throws an error (bad luhn checkdigit).
The validate method will always return the validated value on success π and throw the -errorcode INVALID on error, possibly with additional elements giving you more deets about what went wrong. ngl, very helpful of it.
π API π
The API this package provides satisfies the specification of snit validation types found in the documentation of Snit's Not Incr Tcl. (iykyk)
valtype::luhn 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, iconic behaviour β¨valtype::luhn 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 like, it vibes-checks first, then math π
π ERROR CODES π
Like the package description said, 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. that's the whole point, separating "u typed it wrong" from "we broke it" π
To provide more detailed information about why the validation failed, the -errorCode goes actually beyond that. First, it will contain a code detailing the type itself. Here this is LUHN. 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 LUHN 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 LUHN checkdigit. bestie typed a letter. we noticed. πINVALID LUHN 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, "th input" β the original page says it like that, and I am not editing it, character for character, periodt.) π
π 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 [http://core.tcl.tk/tcllib/reportlist]. Please also report any ideas for enhancements you may have for either package and/or documentation. we love a bug report, we love a glow-up idea, drop them both π«Ά
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. that's the button. the left-most one. you got this π
π₯ KEYWORDS π₯
Checking, Testing, Type checking, Validation, Value checking, isA, luhn
π¦ CATEGORY π¦
Validation, Type checking
β COPYRIGHT β
Copyright (c) 2011 Andreas Kupries <andreas_kupries@users.sourceforge.net>
and that's the whole page bestie π it's tcllib, version 1.1, from the valtype::luhn(3tcl) corner of the manual β go validate something, you're doing amazing, 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