Fomatting Text & Credit Card Validation

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.
 
F

Frank Drebin

string strCCNum = "1234123412341234";

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

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

Sherif ElMetainy

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
 
M

Michelle A.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top