473,396 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Fomatting Text & Credit Card Validation

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
4 3654
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: kaptain kernel | last post by:
I'm implementing a simple credit card number check on my website, in order to trap user errors. it doesn't validate with the bank, but validates against certain known rules (e.g. Amex always begins...
3
by: Justin Koivisto | last post by:
OK, I know a few of you out there use OSC and many of you have also modified it a bit, so I am hoping someone has done something similar... I have the CC payment module installed, not a problem...
3
by: solomon_13000 | last post by:
> Wonthaggi Civic Theatre 'WCT' Case Study > > The town of Wonthaggi has a theatre which is owned and > operated by the local council, it is called the > Wonthaggi Civic Theatre (WCT) and a wide...
10
by: dries | last post by:
A friend of mine has a problem with his credit card validation routine and it is probably a simple thing to solve but I cannot find it. It has to do with the expiry dates. What happens is that as...
19
by: dmiller23462 | last post by:
Hi guys....I have absolutely NO IDEA what I'm doing with Javascript but my end result is I need two text boxes to stay hidden until a particular option is selected....I've cobbled together the...
7
by: gj | last post by:
I have an application in Access 97 I will be rewriting in the latest version of Access in 6 months. In the meantime, does anyone know of an ActiveX control I can add into an Access 97 form to...
7
by: Sandy | last post by:
I need a credit card validator. Is there reliable code already written that anyone knows of? I have come across a few things; i.e. the Luhn-10 algorithm, but don't know if that still applies or...
1
by: Bill D'Innocenzo | last post by:
There are many functions available that implement credit card identification and number validation -- meaning you can decide, based on the number, if a card is a MasterCard or Visa and if the...
1
by: securedcardss | last post by:
http://card.2youtop.info secured credit card card credit instant secured card cash credit secured card
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.