By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,045 Members | 1,305 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,045 IT Pros & Developers. It's quick & easy.

Fomatting Text & Credit Card Validation

P: n/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.
Nov 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
string strCCNum = "1234123412341234";

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

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

"Michelle A." <me@me.com> wrote in message
news:OS**************@tk2msftngp13.phx.gbl...
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.

Nov 17 '05 #2

P: n/a
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

"Michelle A." <me@me.com> wrote in message
news:OS**************@tk2msftngp13.phx.gbl...
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.

Nov 17 '05 #3

P: n/a
I didn't read that second part - about a validation tool.. there is a
formula.. I just started writing about how I don't remember, but I just
looked on google.. here ya go:

http://groups.google.com/groups?hl=e...0f0fae6&rnum=1
(careful for wrapping)

So will basically tell you what kind of card it is, and immediately if it is
a valid credit card or not...
"Michelle A." <me@me.com> wrote in message
news:OS**************@tk2msftngp13.phx.gbl...
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.

Nov 17 '05 #4

P: n/a
Sherif, Frank and Rick.. Thanks for your replies and suggestions. I
appreciate it.
"Rick Spiewak" <ri*********@mindspring.com> wrote in message
news:eb**************@tk2msftngp13.phx.gbl...
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." <me@me.com> wrote in message
news:OS**************@tk2msftngp13.phx.gbl...
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.


Nov 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.