Fomatting Text & Credit Card Validation

  • Thread starter Thread starter Michelle A.
  • Start date Start date
M

Michelle A.

I have a form that takes in a credit card number, just a series of numbers
1234123412341234. When they get to the "Review" page and display all the
information a user has entered, I would like the number to be formatted in a
XXXX-XXXX-XXXX-1234 type of format.

Any good suggestions how to do this?

Anyone out there use that credit card validation tool from to MS downloads
for Visual Studio..? Easy..? Not worth the time?

Thanks.
 
string strCCNum = "1234123412341234";

string strLastFour = strCCNum.Substring(strCCNum.Length-4,4);

string strOutput = "XXXX-XXXX-XXXX-" + strLastFour;
 
Hello

Assuming that the string length is validated to be 16 digits, you can format
it using this code

string formated = cc.Insert(12, "-").Insert(8, "-").Insert(4, "-");
where cc is the string holding the credit card number.

or better to avoid creating many strings

StringBuilder strbld = new StringBuilder(cc, 17);
string formated = strbld.Insert(12, '-').Insert(8, '-').Insert(4,
'-').ToString();

As for your second question about credit card validation tool, I don't know
it, sorry.

Regards
 
Sherif, Frank and Rick.. Thanks for your replies and suggestions. I
appreciate it.


Rick Spiewak said:
You can use a regular expression validator to validate credit cards,
depending on the kind of card. Here's the code I use:

Private Sub dlCreditCardType_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
dlCreditCardType.SelectedIndexChanged

validate_Card()

End Sub

Private Sub validate_Card()

Dim sValidate As String

Select Case dlCreditCardType.SelectedItem.Value

Case "AMEX"

sValidate = "^(3[4,7]\d{2})(-?|\040?)\d{6}(-?|\040?)\d{5}$"

Case "Visa"

sValidate = "(4\d{3})(-?|\040?)(\d{4}(-?|\040?)){3}$"

Case "MasterCard"

sValidate = "(5[0-5]\d{2})(-?|\040?)(\d{4}(-?|\040?)){3}$"

Case "Discover"

sValidate = "(6011)(-?|\040?)(\d{4}(-?|\040?)){3}$"

End Select

Me.regEXCC.ValidationExpression = sValidate

Me.Validate()

End Sub



Michelle A. said:
I have a form that takes in a credit card number, just a series of numbers
1234123412341234. When they get to the "Review" page and display all the
information a user has entered, I would like the number to be formatted
in
a
XXXX-XXXX-XXXX-1234 type of format.

Any good suggestions how to do this?

Anyone out there use that credit card validation tool from to MS downloads
for Visual Studio..? Easy..? Not worth the time?

Thanks.
 
Back
Top