in reply to Re: Formatting with sprintf
in thread Formatting with sprintf

This is a CGI script. I am validating a credit card number ($cardNum) and trying to format it to look like this: 1234-5678-9012-3456. I have confirmed that $cardNum contains a correct, 16-digit value. All attempts have resulted in either null or all zero format (0000-0000-0000-0000). Wish I were smarter....

Replies are listed 'Best First'.
Re^3: Formatting with sprintf
by BillKSmith (Monsignor) on Nov 10, 2015 at 04:50 UTC
    I know this is somewhat off-topic. You should consider using the module Regexp::Common::CC for credit card validation. Unfortunately, the SYNOPSIS is incomplete. You have to check the source code for the complete list of supported credit cards.
    Bill
Re^3: Formatting with sprintf
by citabriabob (Novice) on Nov 10, 2015 at 02:40 UTC
    Someone asked about the version: This is perl, v5.8.8 built for x86_64-linux-thread-multi

      5.8.8 is waaaaay old.

      That's why

      my $CCformatted = $card =~ s/....\K\B/-/gr;

      doesn't work, the /r came along in 5.14.

      my $CCformatted = join '-', $card =~ /..../g;

      should still work.

        $CCformatted = join '-', $cardNum =~ /..../g; still does not work. I have asked host to update Perl to 5.22.0.