Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 54031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:09:23+00:00 2026-05-10T17:09:23+00:00

Given a credit card number and no additional information, what is the best way

  • 0

Given a credit card number and no additional information, what is the best way in PHP to determine whether or not it is a valid number?

Right now I need something that will work with American Express, Discover, MasterCard, and Visa, but it might be helpful if it will also work with other types.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T17:09:23+00:00Added an answer on May 10, 2026 at 5:09 pm

    There are three parts to the validation of the card number:

    1. PATTERN – does it match an issuers pattern (e.g. VISA/Mastercard/etc.)
    2. CHECKSUM – does it actually check-sum (e.g. not just 13 random numbers after ’34’ to make it an AMEX card number)
    3. REALLY EXISTS – does it actually have an associated account (you are unlikely to get this without a merchant account)

    Pattern

    • MASTERCARD Prefix=51-55, Length=16 (Mod10 checksummed)
    • VISA Prefix=4, Length=13 or 16 (Mod10)
    • AMEX Prefix=34 or 37, Length=15 (Mod10)
    • Diners Club/Carte Prefix=300-305, 36 or 38, Length=14 (Mod10)
    • Discover Prefix=6011,622126-622925,644-649,65, Length=16, (Mod10)
    • etc. (detailed list of prefixes)

    Checksum

    Most cards use the Luhn algorithm for checksums:

    Luhn Algorithm described on Wikipedia

    There are links to many implementations on the Wikipedia link, including PHP:

    <? /* Luhn algorithm number checker - (c) 2005-2008 shaman - www.planzero.org *  * This code has been released into the public domain, however please      *  * give credit to the original author where possible.                      */  function luhn_check($number) {    // Strip any non-digits (useful for credit card numbers with spaces and hyphens)   $number=preg_replace('/\D/', '', $number);    // Set the string length and parity   $number_length=strlen($number);   $parity=$number_length % 2;    // Loop through each digit and do the maths   $total=0;   for ($i=0; $i<$number_length; $i++) {     $digit=$number[$i];     // Multiply alternate digits by two     if ($i % 2 == $parity) {       $digit*=2;       // If the sum is two digits, add them together (in effect)       if ($digit > 9) {         $digit-=9;       }     }     // Total up the digits     $total+=$digit;   }    // If the total mod 10 equals 0, the number is valid   return ($total % 10 == 0) ? TRUE : FALSE;  } ?> 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 74k
  • Answers 74k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer The viEmu page itself has a pretty good article that… May 11, 2026 at 2:15 pm
  • added an answer Synergy doesn't allow you to move windows between machines (that… May 11, 2026 at 2:15 pm
  • added an answer A type must always exist in an Assembly - so… May 11, 2026 at 2:15 pm

Related Questions

Given a specific DateTime value, how do I display relative time, like: 2 hours
Given a Python object of any kind, is there an easy way to get
Given a select with multiple option's in jQuery. $select = $(<select></select>); $select.append(<option>Jason</option>) //Key =
Given a DateTime representing a person's birthday, how do I calculate their age in
I'm working on an application where users have to make a call and type
I need to write a web application using SQL Server 2005, asp.net, and ado.net.
I have a right outer join, that almost does what I want... SELECT users_usr.firstname_usr,
I have a question about this question . I posted a reply there but

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.