Tuesday 10 March 2015

Credit Card validation regex script in PHP using Luhn algorithm


Credit card validation is essential for e-commerce websites. Credit card numbers entered by users will not be necessarily correct always. The credit card payment processing companies (visa,mastercard) charge merchandise for each transaction carried out. This also includes the failed transactions. Therefore it becomes essential to validate the credit card number before sending it to the payment gateways. The unique credit card numbers are generated by the issuing banks using "Luhn formula". This tutorial explains how to validate the credit card number entered by user and get the name of the payment network (visa, mastercard etc..) of the credit card. There are different formats for the credit card numbers allotted by the payment networks. The various payment networks and their credit card number formats are given below.