Closed (fixed)
Project:
Private Number
Version:
5.x-1.0
Component:
Miscellaneous
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
18 Feb 2008 at 16:31 UTC
Updated:
11 Oct 2011 at 14:58 UTC
Hi,
what would the pattern be for credit cards?
I'm trying to validate credit card field, and Private number looks like the best module. But can not figure out how to build a pattern for a credit card (especially since there are more than one kind of credit card, each with a different pattern)?
or maybe there's a different cck field type I should use?
Thanks in advance for your help!
:)
Scott
Comments
Comment #1
john.money commentedHi Scott.
I am in the process of updating Private Number and will be sure to include some documentation about credit card regex in the next releae. There can be quite a bit of logic behind credit card validation, so there will likely not be a one-size-fits-all regex solution. For example, here is some code I dug up from a prior ecommerce project:
I found the following regex for Amex, Visa and Mastercard (not Discover or Diners) which does not capture the nuances of the above code, but might work as a first pass. I have yet to test it:
Comment #2
john.money commentedhttp://www.regular-expressions.info/creditcard.html
Comment #3
hacmx commentedThis pattern work for me:
For Visa, MasterCard :
((4\d{3})|(5[1-5]\d{2}))( |)?\d{4}(\4\d{4}){2}For Visa, MasterCard, Discover:
((4\d{3})|(5[1-5]\d{2})|(6011))( |)?\d{4}(\5\d{4}){2}based on: http://www.explainth.at/en/re/repats.shtml
cheers!