Created
July 23, 2018 09:58
-
-
Save manojnaidu619/56c86fce024e8e446408167668e5ef95 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
puts "Enter Credit card Number" | |
input = gets.to_s | |
if input =~ /[a-zA-Z[<>%\$~``!@#^&*()+=?;:{}\|''""'"]]/ # REGEX to validate Card Number | |
puts "Invalid Number" | |
else | |
val = input.gsub!(/[\D\s+]/, '') # val is the variable, storing the Card Number | |
if val =~ /^4/ and val.length >= 12 and val.length <= 19 | |
puts "Visa" | |
elsif val =~ /^(5|2)[1-7][0-9]/ and val.length.eql?(16) | |
puts "Mastercard" | |
elsif val =~ /^6[0|2|4|5][14[0-9][0-9]]/ and val.length.eql?(16) | |
puts "Discover" | |
elsif val =~ /^3[4|7][0-9]/ and val.length.eql?(15) | |
puts "American Express" | |
elsif val =~ /^3[5][0-9][0-9]/ and val.length >= 16 and val.length <= 19 | |
puts "JCB (Japan Credit Bureau)" | |
elsif val =~ /^(5|6)[0-9][0-9]/ and val.length >= 12 and val.length <= 19 | |
puts "Maestro" | |
elsif val =~ /^3[0|6|8][0-9][0-9]/ and val.length.eql?(14) | |
puts "Diners Club Carte Blanche" | |
elsif val =~ /^3[0|9|8][0-9][0-9]/ and val.length.eql?(16) | |
puts "Diners Club International" | |
elsif val =~ /^2[0|1][1|4][4|9][0-9]/ and val.length.eql?(15) | |
puts "enRoute" | |
else | |
puts "The Card issuer is out of our coverage" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment