sounds like you will probably want/need a company that does credit card verifictation. how you write the code to submit it to them usually depends on what company you use for the validation
credit cards usually use the luhn formula to calculate a checkdigit, so you can yourself usually validate whether a number could potentially be a real credit card number, but not that it actually belongs to someone.
also each different credit card company has a different set of digits that their cards begin with, so it is also possible to determine which company issued the card.
but to actually verify the card belongs to someone you will need, as i said in the beginning, a credit card verification company and how you submit the number to them can vary.
here is a class that validates that a particular number could potentially be real. zend