valtype::isbn(n)
π valtype::isbn β the manual page, bestie edition π
okay so this is the manual page for valtype::isbn, which lives in section n of the manual (the Tcl command section, iykyk). it's all about checking whether a string is a real ISBN or just vibes. let's get into it π¦
β¨ NAME β¨
valtype::isbn β validation for ISBN π
πΈ SYNOPSIS πΈ
package require Tcl 8.5 9
package require snit 2
package require valtype::common
package require valtype::isbn ?1.1?
valtype::isbn validate value
valtype::isbn checkdigit value
valtype::isbn 13of value
π DESCRIPTION π
so this package ships a snit validation type for an ISBN. that's the whole job. she's focused. she's employed. periodt.
now, a validation type is basically an object you can point at Tcl values of some particular kind and be like "is this one of those?" fr fr. for example, snit::integer β a validation type that the snit package defines β exists so you can check that a Tcl value is an integer.
every validation type has a validate method, and that's the one doing the actual checking. the rules are:
- it takes a single argument: the value being validated
- if the value is valid, it does nothing
- if the value is invalid, it throws an error
like so:
valtype::isbn validate .... ;# Does nothing
valtype::isbn validate .... ;# Throws an error (bad ISBN).
and here's the glow-up detail: validate always returns the validated value when it succeeds π«Ά, and when it fails it throws with -errorcode INVALID, possibly with extra elements riding along that give you more deets about what went wrong. not me being thorough π
π API π
the API this package gives you satisfies the spec for snit validation types, which lives in the docs for Snit's Not Incr Tcl. no cap.
valtype::isbn validate valueβ validates thevalueand hands it back, possibly in a canonical form, if it passes. if it does not pass, an error gets thrown. simple as.valtype::isbn checkdigit valueβ computes a check digit forvalue. before it does any of that, it validates the value β except for the checkdigit itself, she's skipping that part. and if the value fails validation? no check digit for you, an error instead. πvaltype::isbn 13of valueβ expects an old-style 10-digit ISBN and returns the canonical modern 13-digit ISBN.validateuses this to canonicalize the input, so that every other part of the system downstream can just assume it's working with modern 13-digit ISBNs. it's giving β¨glow-up transformationβ¨ honestly.
π ERROR CODES π
like the package description said: when these commands hit an input validation failure, the error they throw uses -errorcode INVALID to set itself apart from the package's own internal errors.
but wait, there's more β to give you richer info about why validation flopped, the -errorCode actually goes beyond just that. first it carries a code detailing the type itself. here, that's ISBN. then it's followed by values detailing the reason for the failure. the full set of -errorCodes this package can throw is:
INVALID ISBN CHARACTERβ the input had one or more bad characters, i.e. characters that literally must not show up in the input for it to be an ISBN. not allowed, bestie.INVALID ISBN CHECK-DIGITβ the check digit of the input is wrong. this usually means a data-entry oopsie β digits transposed, forgotten, that whole situation. of course, the input could just be an outright fake too. πINVALID ISBN LENGTHβ the input is the wrong length to be an ISBN. she's just not the right size for this.
π BUGS, IDEAS, FEEDBACK π
this document, and the package it describes, will undoubtedly contain bugs and other problems. it's a manual page, they all do. please report such things in the category valtype of the Tcllib Trackers at http://core.tcl.tk/tcllib/reportlist. and please also report any ideas for enhancements you have for either the package and/or the documentation β we want the thoughts π«Ά
if you're proposing code changes, please provide unified diffs, i.e. the output of diff -u.
also note: attachments are strongly preferred over inlined patches. you can attach stuff by going to the Edit form of the ticket immediately after creating it, then using the left-most button in the secondary navigation bar. that's the one. π
β KEYWORDS β
Book Number, Checking, EAN, EAN13, European Article Number, ISBN, International Article Number, International Standard Book Number, Testing, Type checking, Validation, Value checking, isA
π 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 of valtype::isbn(n), brought to you with love. go validate something. slay π
β¨
π¦ 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