valtype::luhn(3tcl)

πŸ“¦
version 2.0 Β· 2 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– 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 (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