Skip to content

Instantly share code, notes, and snippets.

@AlexandrBasan
Created April 9, 2015 04:05
Show Gist options
  • Save AlexandrBasan/582cde2677be0f41beee to your computer and use it in GitHub Desktop.
Save AlexandrBasan/582cde2677be0f41beee to your computer and use it in GitHub Desktop.
Credit card check using REGEX
def card_number_format
case card_type.downcase
when 'visa'
/^4\d{3}\d{4}\d{4}\d{4}$/
when 'mastercard'
/^5[1-5]\d{2}\d{4}\d{4}\d{4}$/
when 'american express'
/^3[4,7]\d{13}$/
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment