CC_DISCOVER(n)
π³ valtype::creditcard::discover(n) β Validation types
okay bestie, gather round, because this is the manual page for valtype::creditcard::discover from the Validation types corner of the Tcllib universe. It lives in section n of the manual, and it's here to do one (1) job and do it slay: tell you whether a string is a real, honest-to-god Discover creditcard number. π
β¨ NAME β¨
valtype::creditcard::discover β Validation for Discover creditcard number
β¨ SYNOPSIS β¨
package require Tcl 8.5 9
package require snit 2
package require valtype::common
package require valtype::luhn
package require valtype::creditcard::discover ?1.1?
valtype::creditcard::discover validate value
valtype::creditcard::discover checkdigit value
β¨ DESCRIPTION β¨
So this package implements a snit validation type for a Discover creditcard number. That's the whole vibe. π
A validation type, for anyone who hasn't met one yet, is literally just an object you can use to validate Tcl values of a particular kind. Like, snit::integer β a validation type that the snit package itself defines β is the thing you use to check that a Tcl value is actually an integer. Same energy, different data. π§
Every single validation type has a validate method, and that's the one doing the actual validation. House rules for it: it must take a single argument β the value to be validated β and it must do nothing at all if the value is valid, but throw an error if the value is invalid:
valtype::creditcard::discover validate .... ;# Does nothing
valtype::creditcard::discover validate .... ;# Throws an error (bad Discover creditcard number).
And here's the cute part: validate will always return the validated value when it succeeds, and it throws the -errorcode INVALID when it fails β possibly with extra elements tacked on that spill more tea about what exactly went wrong. π
β¨ API β¨
The API this package hands you satisfies the spec for snit validation types found in the documentation of Snit's Not Incr Tcl. No cap.
valtype::creditcard::discover validate valueβ This method validates the value and returns it, possibly in a canonical form, if it passes. And if the value does not pass the validation? An error gets thrown. That's it, that's the deal. π«Άvaltype::creditcard::discover checkdigit valueβ This method computes a check digit for the value. But before it does any of that, the value gets validated β except for a checkdigit. So if the value doesn't pass validation, no check digit is calculated at all, and an error is thrown instead. Sorry bestie, no math for bad input. π
β¨ ERROR CODES β¨
Like the package description already said: when the commands in this package get input that fails validation, the errors they throw use the -errorcode INVALID so you can tell them apart from the package's own internal errors. Iconic behaviour, honestly. β
But wait, there's more, because the -errorCode goes actually beyond that to give you the detailed reason why the validation failed. First it carries a code detailing the type itself β and here that's CREDITCARD DISCOVER. Then values follow that detail the reason for the failure. The full set of -errorCodes this package can throw is:
INVALID CREDITCARD DISCOVER 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 Discover creditcard number. Rude little gremlin characters. πINVALID CREDITCARD DISCOVER 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. π©INVALID CREDITCARD DISCOVER LENGTHβ The input value is of the wrong length to be a Discover creditcard number.INVALID CREDITCARD DISCOVER PREFIXβ The input value does not start with the magic value(s) required for it to be a Discover creditcard number. β¨
β¨ BUGS, IDEAS, FEEDBACK β¨
Okay so real talk: this document, and the package it describes, will undoubtedly contain bugs and other problems. That's just how it is. So please report such in the category valtype of the Tcllib Trackers at [http://core.tcl.tk/tcllib/reportlist]. And please also report any ideas for enhancements you may have for either package and/or documentation β they want to hear it, fr fr. π
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.
β¨ KEYWORDS β¨
Checking, Discover, Testing, Type checking, Validation, Value checking, bank, card for credit, credit card, finance, isA
β¨ CATEGORY β¨
Validation, Type checking
β¨ COPYRIGHT β¨
Copyright (c) 2011 Andreas Kupries <andreas_kupries@users.sourceforge.net>
okay that's the whole page, no notes π
the synopsis commands and every -errorCode are copied exactly, so you can trust them with your life.
and that's a wrap bestie!! π¦ this little icon came from tcllib, version 1.1, and the copyright belongs to Andreas Kupries (c) 2011 β go forth and validate those card numbers, main character πβ¨πΈ
π¦ 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