Handbook
Glossary
v-credit-card ( str -- n )
Form validators
Prev:
v-password ( str -- str )
Next:
v-mode ( str -- str )
Vocabulary
validators
Inputs
str
a
string
Outputs
n
an
integer
Word description
If the credit card number passes the Luhn algorithm, converts it to an integer, otherwise throws an error.
Notes
See
http://en.wikipedia.org/wiki/Luhn_algorithm
for a description of this algorithm.
Definition
USING:
kernel
math.parser
ranges
sequences
sets
;
IN:
validators
:
v-credit-card
( str -- n )
"- "
without
dup
48 57
[a..b]
diff
empty?
[
13
v-min-length
16
v-max-length
dup
luhn?
[
string>number
]
[
"card number check failed"
throw
]
if
]
[
"invalid credit card number format"
throw
]
if
;