valtype::c...:mastercard(3tcl)

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

✨ valtype::creditcard::mastercard β€” the glow-up ✨

okay bestie, you're in the valtype::c...:mastercard page of the 3tcl manual, and it's literally all about checking whether a Mastercard creditcard number is actually valid πŸ’³πŸ’… no cap.


🌸 NAME 🌸

valtype::creditcard::mastercard β€” Validation for Mastercard 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::mastercard ?1.1?

valtype::creditcard::mastercard validate value

valtype::creditcard::mastercard checkdigit value

πŸ’– DESCRIPTION πŸ’–

so this package ships a snit validation type for a Mastercard creditcard number, periodt.

A validation type is, like, an object that validates Tcl values of a particular kind. For example, snit::integer β€” a validation type defined by the snit package β€” is what you use to validate that a Tcl value is an integer. iconic behaviour honestly.

Every validation type has a validate method, and that's the main character that does the actual validating. It has to take a single argument β€” the value to be validated β€” and bestie listen: it must do nothing if the value is valid, but throw an error if the value is invalid:

valtype::creditcard::mastercard validate .... ;# Does nothing
valtype::creditcard::mastercard validate .... ;# Throws an error (bad Mastercard creditcard number).

The validate method will always return the validated value on success, and throw the -errorcode INVALID on error β€” possibly with extra elements attached that give you more details about what went wrong πŸ™ˆ


πŸ‘‘ API πŸ‘‘

The API this package serves up satisfies the spec of snit validation types found in the documentation of Snit's Not Incr Tcl. slay.

  • valtype::creditcard::mastercard 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. simple as that πŸ’…
  • valtype::creditcard::mastercard checkdigit value β€” This method computes a check digit for the value. Before it does any of that, the value gets validated β€” except for a checkdigit. If the value doesn't pass validation, then no check digit gets calculated at all, and an error is thrown instead. no check digit for you, bestie 😭

πŸ’€ ERROR CODES πŸ’€

Like the package description already said, the errors thrown by the commands of this package when input validation fails use -errorcode INVALID to tell themselves apart from the package's own internal errors. vibe check: INVALID means you did something, not the package.

And to give you more detailed tea about why the validation failed, the -errorCode actually goes beyond that. First, it contains a code detailing the type itself β€” here that's CREDITCARD MASTERCARD. Then values follow detailing the reason for the failure. The full set of -errorCodes this package can throw:

  • INVALID CREDITCARD MASTERCARD 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 Mastercard creditcard number. not the vibe. 🚫
  • INVALID CREDITCARD MASTERCARD CHECK-DIGIT β€” The check digit of the input value is wrong. This usually signals a data-entry error β€” digits transposed, forgotten, etc. Of course, th input may be an outright fake too. πŸ‘€
  • INVALID CREDITCARD MASTERCARD LENGTH β€” The input value is of the wrong length to be a Mastercard creditcard number. too short, too long, whatever β€” it's giving wrong size πŸ“
  • INVALID CREDITCARD MASTERCARD PREFIX β€” The input value does not start with the magic value(s) required for it to be a Mastercard creditcard number. wrong opening act, bestie ✨

🫢 BUGS, IDEAS, FEEDBACK 🫢

This document, and the package it describes, will undoubtedly contain bugs and other problems β€” ngl, it's a whole thing. 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. iykyk πŸŽ€


🌈 KEYWORDS 🌈

Checking, MasterCard, 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 the whole page, bestie β€” every option, every error code, every word, no details left behind πŸ’œ

tcllib, version 1.1 β€” mwah, tysm for reading, slay the day πŸ’…βœ¨πŸŒΈ

πŸ“¦ where this page comes from