Hackerss.com is a community of amazing hackers

Hackerss is a community for developers, data scientitst, ethical hackers, hardware enthusiasts or any person that want to learn / share their knowledge of any aspect of digital technology.

Create account Log in

Posted on

Php Validate credit card number using regex

function validateCreditCard($cc_number) {
  // regex for credit card number
  $regex = '/^[0-9]{13,16}$/';
  // check if the credit card number matches the regex
  if (preg_match($regex, $cc_number)) {
    // return true if it matches
    return true;
  } else {
    // return false if it doesn't match
    return false;

$result = validateCreditCard('1234567890123456');

echo $result; //true

Enter fullscreen mode Exit fullscreen mode

Top comments (0)