valtype::luhn5(n)
π valtype::luhn5(n) β Validation types π
okay bestie, welcome to the valtype::luhn5 page, straight out of the tcllib manual, "Validation types" section. this one is all about validating a plain number that's carrying a LUHN5 checkdigit. buckle up π
β¨ NAME β¨
valtype::luhn5 β validation for a plain number with a LUHN5 checkdigit. that's the whole vibe. π¦
πΈ 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
π DESCRIPTION π
so. this package implements a snit validation type for a plain number with a LUHN5 checkdigit. no cap, that's literally what it does.
a validation type is an object you can use to validate Tcl values of a particular kind. like, for example, snit::integer β that's a validation type defined by the snit package β and it's used to validate that a Tcl value is an integer. same energy, different flavour. β¨
every validation type has a validate method, and that method is the one doing the actual validating. it must take a single argument: the value to be validated. and then β and this is the iconic part β it must do nothing if the value is valid, but throw an error if the value is invalid:
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 it throws the -errorcode INVALID on error, possibly with additional elements giving you more deets about what went wrong.
π API π
the API this package hands you satisfies the spec of snit validation types found in the documentation of Snit's Not Incr Tcl. periodt.
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 gets thrown. that's it, that's the method. πvaltype::luhn5 checkdigit valueβ this method computes a check digit for the value. before doing that, it validates the value, except for a checkdigit. so if the value doesn't pass validation, no check digit gets calculated at all and an error is thrown instead. no check digit for you π
π ERROR CODES π
like the package description already said, the errors thrown by this package's commands in response to input validation failures use the -errorcode INVALID to distinguish themselves from package internal errors. it's giving "not like the other errors". π
and to give you more detailed info about why the validation failed, the -errorCode actually goes beyond that. first, it contains a code detailing the type itself. here, that's LUHN5. that's then followed by values detailing the reason for the failure. the full set of -errorCodes this package can throw is:
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. π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. π©
π BUGS, IDEAS, FEEDBACK π
this document, and the package it describes, will undoubtedly contain bugs and other problems. no shade, it's just how docs are. 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 β we love a glow-up suggestion. π«Ά
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. go off. π
β 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 was tcllib version 1.1, the valtype::luhn5(n) manual page from the "Validation types" section β go forth and validate those checkdigits, you absolute icon ππβ¨
π¦ where this page comes from
- fedora 43: tcllib 2.0-3.fc43 Β· TCL
- fedora 44: tcllib 2.0-4.fc44 Β· TCL
- nixos 26.05: tcllib 2.0
- nixpkgs unstable: tcllib 2.0
- 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