Created
April 9, 2015 04:05
-
-
Save AlexandrBasan/582cde2677be0f41beee to your computer and use it in GitHub Desktop.
Credit card check using REGEX
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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