If you would like to make some extra cash for surfing the web, jump to http://www.codeoftheweek.com/paidsurf.html
In this issue we discuss how properly (at least in our opinion) format credit card numbers. This routine is useful for anyplace a credit card number is captured or displayed. It should work well in VBScript with very little modifications.
If you have any questions about using this module, let us know at firstname.lastname@example.org
This module contains a single routine called FormatCreditCardNumber that takes a string of digits and processes it to produce a nicely formatted credit card number.
Public Function FormatCreditCardNumber(sCardNumber As String, Optional bSecure As Boolean = False) As String
This function returns a formatted credit card number using separate formats for the different types of credit/charge cards. An American Express card is 15 digits and has the number grouped differently than Visa, MasterCard and Novus cards. The default number separator is a - (dash). If you want the return string to show a secure representation of the card number just set the bSecure option to True. This will cause this function to put X characters in the place of all numbers except the last four digits.
American Express numbers will be formatted as 1234-123456-12345. All others will be formatted as 1234-1234-1234-1234.
One really nice feature of this routine is that the input string specified by sCardNumber can be any format as long as it has 15 or 16 digits. For example, 1111-1111-2222-2222 or 11111111 222 2 2222 would result in the same output string. The routine "cleans" the string first by removing any non-numeric character and then reformats it according to the specific rules defined in this function. This is REALLY useful for those web sites that gather information from users that can enter numbers any way they wish.
Some examples are shown using different credit card numbers (NOTE: the credit card numbers are not real card numbers).
Debug.Print FormatCreditCardNumber("4234123412341234") ' will print out as 4234-1234-1234-1234 Debug.Print FormatCreditCardNumber("4234123412341234",True) ' will print out as XXXX-XXXX-XXXX-1234 Debug.Print FormatCreditCardNumber("323412341234123",True) ' will print out as XXXX-XXXXXX-X4123
To see the source code for this issue you must be a subscriber to Code of the Week. If you are a subscriber the source code is available at the following address: http://www.codeoftheweek.com/membersonly/bi/0118.html
If you would like to get paid for surfing the web, jump to http://www.codeoftheweek.com/paidsurf.html