Groovy Credit Card Number ValidationBack in March I attended a software conference hosted in St. Louis called No Fluff, Just Stuff. The lectures introduced me to some cool new technology. It was small and intimate. I had an opportunity to speak to the instructors and conference organizer. class LuhnValidator {
def isValidCreditCardNumber(number) {
def sum = 0
def alternate = false
number.reverse().each { value ->
if (value =~ /\d/)
{
def n = value.toInteger()
if (alternate) {
n *= 2
if (n > 9) {
n = n % 10 + 1
}
}
sum += n
alternate = !alternate
}
}
sum % 10 == 0
}
}
Posted at 9:16 PM
|
Search
Recent Entries
Creative Limit
Archon 32 Recap Trip Back Home You're Gonna Pi, Pi, Pi Blues on Purpose Tabriz School of Magick Spycraft LARP Video Read a Book The Great Divorce JavaOne 2008 Report, Part 4: Friday (Older Entries) Other Journals
License
RSS Feed
|