CC_AMEX(3tcl)

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

πŸ’³ NAME πŸ’³

okay so this is valtype::creditcard::amex from the valtype::creditcard::amex(3tcl) manual page, filed under Validation types, and it's literally the validation for AMEX creditcard numbers. no cap. πŸ’³βœ¨


πŸ“¦ SYNOPSIS πŸ“¦

package require Tcl 8.5 9

package require snit 2

package require valtype::common

package require valtype::luhn

package require valtype::creditcard::amex ?1.1?

valtype::creditcard::amex validate value

valtype::creditcard::amex checkdigit value

πŸ’– DESCRIPTION πŸ’–

so this package is a snit validation type for AMEX creditcard numbers, bestie. that's the whole vibe. 🫢

a validation type is basically an object you can use to check that Tcl values are a particular kind of thing. like, snit::integer β€” a validation type that the snit package defines β€” is the one you'd use to make sure some Tcl value is an integer. same energy, but for cards. πŸ’…

every validation type has a validate method and that's the one doing the actual checking. it takes exactly one argument: the value you wanna validate. and it must do nothing if the value is valid, but throw an error if the value is invalid. like:

valtype::creditcard::amex validate .... ;# Does nothing
valtype::creditcard::amex validate .... ;# Throws an error (bad American Expresss creditcard number).

and on success, validate always returns the validated value. on failure it throws -errorcode INVALID, and sometimes there's extra stuff in there giving you more deets about what went wrong. 😭


πŸ›  API πŸ› 

the API this package gives you satisfies the spec of snit validation types, which lives in the documentation of Snit's Not Incr Tcl. periodt. πŸ‘‘

  • valtype::creditcard::amex validate value β€” validates the value and returns it (possibly in a canonical form) if it passes. if it doesn't pass, an error gets thrown. that's it, that's the method. ✨
  • valtype::creditcard::amex checkdigit value β€” computes a check digit for the value. before it does that, it validates the value β€” except for a checkdigit. so if the value flops the validation, no check digit gets calculated and you get an error instead. πŸ™ˆ

🚨 ERROR CODES 🚨

like the package description said: when these commands get input that fails validation, the errors they throw use -errorcode INVALID, which is how they keep themselves separate from the package's own internal errors. iconic behaviour honestly.

and to give you the full tea on why validation failed, the -errorCode goes beyond just that. first it contains a code detailing the type itself β€” here that's CREDITCARD AMEX. then it's followed by values detailing the reason for the failure. the complete set of -errorCodes this package can throw is:

  • INVALID CREDITCARD AMEX CHARACTER β€” the input value had one or more bad characters, i.e. characters that must not show up in the input for it to be an AMEX creditcard number. 🚫
  • INVALID CREDITCARD AMEX CHECK-DIGIT β€” the check digit of the input value is wrong. this usually means a data-entry error, digits transposed, forgotten, etc. and yeah, of course, the input could just be an outright fake too. πŸ’€
  • INVALID CREDITCARD AMEX LENGTH β€” the input value is the wrong length to be an AMEX creditcard number. πŸ“
  • INVALID CREDITCARD AMEX PREFIX β€” the input value doesn't start with the magic value(s) required for it to be an AMEX creditcard number. πŸͺ„

πŸ› BUGS, IDEAS, FEEDBACK πŸ›

ngl, this document and the package it describes will undoubtedly contain bugs and other problems. it's giving humble but real. so please report them in the category valtype of the Tcllib Trackers: http://core.tcl.tk/tcllib/reportlist. and if you've got ideas for enhancements for either the package and/or the documentation, report those too bestie, we want them. 🫢

when you're proposing code changes, please provide unified diffs, i.e. the output of diff -u. πŸ“

and one more thing: attachments are strongly preferred over inlined patches. you make an attachment by going to the Edit form of the ticket right after creating it, and then using the left-most button in the secondary navigation bar. iykyk. πŸ’…


πŸ”‘ KEYWORDS πŸ”‘

AMEX, American Express, Checking, Testing, Type checking, Validation, Value checking, bank, card for credit, credit card, finance, isA


πŸ—‚ CATEGORY πŸ—‚

Validation, Type checking


Copyright (c) 2011 Andreas Kupries <andreas_kupries@users.sourceforge.net>


and that's a wrap, bestie πŸŽ€ this whole thing ships as tcllib, version 1.1, and the page is valtype::creditcard::amex(3tcl). go validate those cards, slay πŸ’–βœ¨πŸ¦‹

πŸ“¦ where this page comes from