The code below will pass a credit card as being valid if it contains
dashes, spaces, and also alphanumerics. How can I check for only dashes
and spaces and return invalid when the user inputs alphanumerics?
Thanks.
Sub ValidateCCNumber( s As Object, e As ServerValidateEventArgs )
Dim intCounter As Integer
Dim strCCNumber As String
Dim blnIsEven As Boolean = False
Dim strDigits As String = ""
Dim intCheckSum As Integer = 0
'Strip away everything except numerals
FOR intCounter = 1 To Len( e.Value )
IF IsNumeric( MID( e.Value, intCounter, 1 ) ) THEN
strCCNumber = strCCNumber & MID( e.Value, intCounter, 1 )
END IF
NEXT
'IF nothing left, then fail
IF Len( strCCNumber ) = 0 THEN
e.IsValid = False
ELSE
'Double every other digit
FOR intCounter = Len( strCCNumber ) To 1 Step -1
IF blnIsEven THEN
strDigits = strDigits & cINT( MID( strCCNumber, intCounter, 1 )
) * 2
ELSE
strDigits = strDigits & cINT( MID( strCCNumber, intCounter, 1 )
)
END IF
blnIsEven = ( NOT blnIsEven )
NEXT
'Calculate CheckSum
FOR intCounter = 1 To Len( strDigits )
intCheckSum = intCheckSum + cINT( MID( strDigits, intCounter, 1
) )
NEXT
'Assign results
e.IsValid = (( intCheckSum Mod 10 ) = 0 )
END IF
END Sub 2 1235
Look into using regular expressions: http://www.codeproject.com/aspnet/cr...dvalidator.asp http://www.codeproject.com/aspnet/Cr...Validator2.asp http://www.evolt.org/article/Validat...ript/17/24700/
-Brock
DevelopMentor http://staff.develop.com/ballen The code below will pass a credit card as being valid if it contains dashes, spaces, and also alphanumerics. How can I check for only dashes and spaces and return invalid when the user inputs alphanumerics? Thanks.
Sub ValidateCCNumber( s As Object, e As ServerValidateEventArgs ) Dim intCounter As Integer Dim strCCNumber As String Dim blnIsEven As Boolean = False Dim strDigits As String = "" Dim intCheckSum As Integer = 0 'Strip away everything except numerals FOR intCounter = 1 To Len( e.Value ) IF IsNumeric( MID( e.Value, intCounter, 1 ) ) THEN strCCNumber = strCCNumber & MID( e.Value, intCounter, 1 ) END IF NEXT 'IF nothing left, then fail IF Len( strCCNumber ) = 0 THEN e.IsValid = False ELSE 'Double every other digit FOR intCounter = Len( strCCNumber ) To 1 Step -1 IF blnIsEven THEN strDigits = strDigits & cINT( MID( strCCNumber, intCounter, 1 ) ) * 2 ELSE strDigits = strDigits & cINT( MID( strCCNumber, intCounter, 1 ) ) END IF blnIsEven = ( NOT blnIsEven ) NEXT 'Calculate CheckSum FOR intCounter = 1 To Len( strDigits ) intCheckSum = intCheckSum + cINT( MID( strDigits, intCounter, 1 ) ) NEXT 'Assign results e.IsValid = (( intCheckSum Mod 10 ) = 0 ) END IF END Sub
Search Google for a Regular Expression that validates a Credit Card. There
are plenty.
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
"Sparky Arbuckle" <tw*@secureroot.com> wrote in message
news:11**********************@l41g2000cwc.googlegr oups.com... The code below will pass a credit card as being valid if it contains dashes, spaces, and also alphanumerics. How can I check for only dashes and spaces and return invalid when the user inputs alphanumerics? Thanks.
Sub ValidateCCNumber( s As Object, e As ServerValidateEventArgs ) Dim intCounter As Integer Dim strCCNumber As String Dim blnIsEven As Boolean = False Dim strDigits As String = "" Dim intCheckSum As Integer = 0
'Strip away everything except numerals FOR intCounter = 1 To Len( e.Value ) IF IsNumeric( MID( e.Value, intCounter, 1 ) ) THEN strCCNumber = strCCNumber & MID( e.Value, intCounter, 1 ) END IF NEXT
'IF nothing left, then fail IF Len( strCCNumber ) = 0 THEN e.IsValid = False ELSE
'Double every other digit FOR intCounter = Len( strCCNumber ) To 1 Step -1 IF blnIsEven THEN strDigits = strDigits & cINT( MID( strCCNumber, intCounter, 1 ) ) * 2 ELSE strDigits = strDigits & cINT( MID( strCCNumber, intCounter, 1 ) ) END IF blnIsEven = ( NOT blnIsEven ) NEXT
'Calculate CheckSum FOR intCounter = 1 To Len( strDigits ) intCheckSum = intCheckSum + cINT( MID( strDigits, intCounter, 1 ) ) NEXT
'Assign results e.IsValid = (( intCheckSum Mod 10 ) = 0 )
END IF END Sub This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: sam1967 |
last post by:
I know how to build forms with ASP and process user input.
Now i want to take credit card payments via a form.
i will then download the details and process them via our credit card
machine.
do...
|
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...
|
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...
|
by: Grant |
last post by:
Does any one know how to check the algorithm of the credit card number that
was entered in the text box? I want to be able to make sure the users enter
correct credit card number since we will...
|
by: Michelle A. |
last post by:
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...
|
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...
|
by: tshad |
last post by:
I am looking to connect my asp.net pages to a credit card processor, such as
ICVerify.
I used to be able to read and write to a text file: credit card
authorizations, cancelations, get responses...
|
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...
|
by: securedcardss |
last post by:
http://card.2youtop.info
secured credit card
card
credit instant secured
card cash
credit secured
card
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |