Forum Moderators: coopster

Message Too Old, No Replies

Help with if statement

need to error detect credit card number format

         

stevenjm

1:07 am on Feb 18, 2004 (gmt 0)

10+ Year Member



Am wanting to change an error detection if statement as I want to be able to use Australian credit cards which seem to have a different format in the numbering system.

I assume its this if statement but I am having trouble working it out:

if (ereg('^4[0-9]{12}([0-9]{3})?$', $this->cc_number)) {
$this->cc_type = 'Visa';

could really do with an explanation of this part if anyone can help(it needs to be able to accept a number such as 4564 5555 5555 5555):

('^4[0-9]{12}([0-9]{3})

thanks

ergophobe

5:07 pm on Feb 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It should work fine for the numbers given. Basically the regex looks for numbers that

- start with a 4
- have 12 occurrences of digits
- have 3 more digits which are in a substition group (so they can be reused in a replace operation or something). Since it is followed by the?, it means match it 0 or 1 times (so in other words the expression would match 13 or 16 digit card numbers.

- ^ constrains to beginning of subject/line
- $ constrains to end of subject/line

Tom

stevenjm

10:08 pm on Feb 18, 2004 (gmt 0)

10+ Year Member



Thanks a lot for your help Tom.

Still cannot get it to work though - its an existing script and after digging deeper there is a lot more error detection as well. Every second digit is doubled etc etc. I will just have to crawl through until I find the problem in the other ifs. :)