dreams3577 Posted May 30, 2010 Posted May 30, 2010 Hi All Building on a exsiting payment module to accept UK cards, however I need help with the validation side of things.. The current validation format is like this if (preg_match('/^4[0-9]{12}([0-9]{3})?$/', $this->cc_number)) { $this->cc_type = 'Visa'; } elseif (preg_match('/^5[1-5][0-9]{14}$/', $this->cc_number)) { $this->cc_type = 'Master Card'; } I need to accept the cards below, I have included the variables for each card, where i need help is to write the syntax in the above format for the cards below.. Maestro length => 12,13,14,15,16,18,19 prefixes => 5018,5020,5038,6304,6759,6761 Solo length => 16,18,19 prefixes => 6334,6767 Switch length => 16,18,19 prefixes => 4903,4905,4911,4936,564182,633110,6333,6759 Visa Electron length => 16 prefixes => 417500,4917,4913,4508,4844 Many Thanks Steve Quote
MrPhil Posted May 30, 2010 Posted May 30, 2010 The pattern for Visa says "4 followed by 12 digits (0-9), optionally followed by 3 digits (0-9)". Length is 13 or 16. The pattern for MasterCard says "one of 51 through 55, followed by 14 digits (0-9)". Length is 16. For Maestro, is any length 12-16 or 18-19 OK, starting with one of those prefixes? If so, it depends on whether preg_match() takes "extended" format. Assuming it does, you'll still have to split it up into two tests, to handle the two different length groups. Something like ^(5018|5020|5038|6305|6759|6761)[0-9]{8,12}$ and ^(5018|5020|5038|6305|6759|6761)[0-9]{14,15}$ should work. If the "|" doesn't work, you'd have to break it up into 6 x 2 = 12 tests. If certain lengths correspond to certain prefixes, you'll have to break it up into multiple tests. Likewise, for Solo, ^6(334|767)[0-9]{12}$ and 6(334|767)[0-9]{14,15}$. For Switch, ^(4903|4905|4911|4936|6333|6759)[0-9]{12}$, ^(4903|4905|4911|4936|6333|6759)[0-9]{14,15}$, ^(564182|633110)[0-9]{10}$, and ^(564182|633110)[0-9]{12,13}$. For Visa Electron, ^417500[0-9]{10}$ and ^4(917|913|508|844)[0-9]{12}$. That may not be exact, but it should get you started. By the way, you should not be using the "cc" module that comes with osC. It should not be used for production -- it is very insecure. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.