Re: Looking for a certain regexp

From: Dale Henderson (nilram_at_hotpop.com)
Date: 06/30/04


Date: 30 Jun 2004 15:57:34 -0500


>>>>> "PG" == Purl Gurl <purlgurl@purlgurl.net> writes:

    PG> Abigail wrote:
>> Checksums *can* be checked with a regexp.

    PG> No, they cannot and returns are not a checksum, both within a
    PG> context of credit card number validation.

    PG> Returns are based on a mathematical formula which should
    PG> return zero for modulus ten if a valid number.
     

     The Luhn or "mod 10" formula is essentially a checksum.
     Is just that you know the sum ahead of time i.e. 0.
 

    PG> You cannot use a regex for validating credit card numbers.

     I wouldn't be so quick to say what can't be done with a regular
     expression. Regular expressions (especially Perl regular
     expressions) are very powerful and can even be
     used to check numbers for primality tests and even solve simple
     Diophantine equations.

     For example to test for primality use:

     $p=7; #number to test for primality
     
     $str="1"x$p;
     if(str=~/^(11+)\1+$/){
         print "$p is Composite\n";
     }else{
        print "$p is Prime\n"
     }
     
     Not an efficient test but it works none the less.

     In fact the first step of the Luhn test can be done with:

     $cc=1234567890123456

     $cc=~s/(\d)(\d)/(x==9?9:($1*2)%9).$2/eg;
     
     This assumes the length of $cc is even (for odd length a
     different replacement is needed) and doubles the odd numbered
     digits with appropriate modifications (add the digits of 2 digit
     numbers).

     For the next step putting a plus between the digits and using an
     eval would work.

>> Now, if only I could find the URLs with the checksum formulas

    PG> Too bad you have me killfiled. You could learn from me, just
    PG> as I learn from others. I have almost a decade of experience
    PG> in working with credit card validation.

    PG> http://www.beachnet.com/~hstiles/cardtype.html

    PG> Others will learn from what I share. You will not. In time,
    PG> others will know more than you, just as I know more about this
    PG> topic than you. It is illogical to limit your ability to gain
    PG> knowledge based upon personal bigotry.

    PG> Fix your quoting style; it is as bad as Uri's and Randal's and
    PG> a real chore to repair. Wastes bandwidth to boot.

    How dare you harass Abigail just because she is female. :)

    PG> Purl Gurl

-- 
Dale Henderson 
"Imaginary universes are so much more beautiful than this stupidly-
constructed 'real' one..."  -- G. H. Hardy


Relevant Pages

  • Re: Setting Requirements on Forms
    ... FrontPage uses client-side JavaScript for form validation. ... just having 16 digits doesn't make for a valid ... and in the fields collecting the credit card ...
    (microsoft.public.frontpage.programming)
  • Re: COBOL (Fujitsu v3) Data validation.
    ... my main problem is still validating that the user enters 12 digits only. ... >> I am writing a Credit Card program. ... > Let's leave validation of the input for a moment and go for your specific ... Here's a basic programming rule: ...
    (comp.lang.cobol)
  • RE: form population macro
    ... MsgBox ("Invalid Credit Card Number") ... american express then 15 digits. ... that chooses, Visa, AE ...etc. and I want to have the entry cell change if it ... another is not different than copying data from one worksheet to another ...
    (microsoft.public.excel.programming)
  • RE: form population macro
    ... I'll try to be clearer on the credit card number issue. ... american express then 15 digits. ... that chooses, Visa, AE ...etc. and I want to have the entry cell change if it ... another is not different than copying data from one worksheet to another ...
    (microsoft.public.excel.programming)
  • Re: Dumb Question - Credit Card Number Scanner
    ... 'Just' code up a CC number validation routine. ... Dumb Question - Credit Card Number Scanner ... Start with the first byte on the first disk. ... send email to listserv@xxxxxxxxxxx with the message: GET IBM-MAIN INFO ...
    (bit.listserv.ibm-main)