Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old December 22nd, 2006, 05:15 PM
Rob
Guest
 
Posts: n/a
Default looking for mod 10 script

I'm looking for a mod 10 script that you know to work well. I have googled
and found a few different ones but I would like a 2nd opinion. If you can
please link me to a mod 10 script that you have used/implimented I would
appreciate it.

Ideally I would like a vbscript over javascript so we can have it
implimented on an access db as well.

Thanks.


  #2  
Old December 22nd, 2006, 06:35 PM
Evertjan.
Guest
 
Posts: n/a
Default Re: looking for mod 10 script

Rob wrote on 22 dec 2006 in microsoft.public.inetserver.asp.general:
Quote:
I'm looking for a mod 10 script
You mean a mod10 function, I think.

If not, what is a mod 10 script?
Quote:
that you know to work well. I have
googled and found a few different ones but I would like a 2nd opinion.
If you can please link me to a mod 10 script that you have
used/implimented I would appreciate it.
Jscript:

function mod10function(x){
return x % 10;
};

vbscript:

function mod10function(x)
mod10function = x mod 10
end function
Quote:
Ideally I would like a vbscript over javascript so we can have it
implimented on an access db as well.
"vbscript over javascript" what is that?

Can you implement that on a database, a database being only storage?

Who is "we", ideally?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
  #3  
Old December 22nd, 2006, 07:25 PM
Stefan Berglund
Guest
 
Posts: n/a
Default Re: looking for mod 10 script

On Fri, 22 Dec 2006 09:05:33 -0800, "Rob" <nospam@nospam.comwrote:
in <O90TlteJHHA.3552@TK2MSFTNGP03.phx.gbl>
Quote:
>I'm looking for a mod 10 script that you know to work well. I have googled
>and found a few different ones but I would like a 2nd opinion. If you can
>please link me to a mod 10 script that you have used/implimented I would
>appreciate it.
>
>Ideally I would like a vbscript over javascript so we can have it
>implimented on an access db as well.
>
>Thanks.
>
The best article I found on that subject is still available here:

http://www.sitepoint.com/article/car...tion-class-php

And here is a VBScript version of that.

<%Const CARD_TYPE_MC = 0
Const CARD_TYPE_VS = 1
Const CARD_TYPE_AX = 2
Const CARD_TYPE_DC = 3
Const CARD_TYPE_DS = 4
Const CARD_TYPE_JC = 5

Dim msCCName, msCCType, msCCNumber, msCCExpMonth, msCCExpYear

Function Mod10(sNumber)

Dim CardNumber: CardNumber = StrReverse(sNumber)
Dim NumberSum: NumberSum = 0

Dim lngN
For lngN = 1 To Len(CardNumber)
Dim CurrentNumber: CurrentNumber = Mid(CardNumber, lngN, 1)

' Double every second digit
If (lngN Mod 2 = 0) Then CurrentNumber = CurrentNumber * 2

' Add digits of 2-digit numbers together
If (CurrentNumber 9) Then
Dim FirstNumber: FirstNumber = CurrentNumber Mod 10
Dim SecondNumber: SecondNumber = (CurrentNumber - FirstNumber) / 10
CurrentNumber = FirstNumber + SecondNumber
End If

NumberSum = NumberSum + CurrentNumber
Next

Mod10 = ((NumberSum Mod 10) = 0)

End Function

Function ValidateCreditCard(CCName, CCType, CCNumber, CCExpMonth, CCExpYear)

' http://www.sitepoint.com/print/card-...tion-class-php
'* Mastercard: Must have a prefix of 51 to 55, and must be 16 digits in length.
'* Visa: Must have a prefix of 4, and must be either 13 or 16 digits in length.
'* American Express: Must have a prefix of 34 or 37, and must be 15 digits in length.
'* Diners Club: Must have a prefix of 300 to 305, 36, or 38, and must be 14 digits in length.
'* Discover: Must have a prefix of 6011, and must be 16 digits in length.
'* JCB: Must have a prefix of 3, 1800, or 2131, and must be either 15 or 16 digits in length.

ValidateCreditCard = False
If ((Len(CCName) = 0) Or (Len(CCType) = 0) Or (Len(CCNumber) = 0) Or (Len(CCExpMonth) = 0) Or (Len(CCExpYear) = 0)) Then Exit Function
msCCName = CCName

Select Case LCase(CCType)
Case "mc":
Case "mastercard":
Case "m":
Case "1":
msCCType = CARD_TYPE_MC

Case "vs":
Case "visa":
Case "v":
Case "2":
msCCType = CARD_TYPE_VS

Case "ax":
Case "american express":
Case "a":
Case "3":
msCCType = CARD_TYPE_AX

Case "dc":
Case "diners club":
Case "4":
msCCType = CARD_TYPE_DC

Case "ds":
Case "discover":
Case "5":
msCCType = CARD_TYPE_DS

Case "jc":
Case "jcb":
Case "6":
msCCType = CARD_TYPE_JC

Case Else
Exit Function
End Select

Dim regEx: Set regEx = New RegExp
regEx.Pattern = "[^0-9]"
regEx.IgnoreCase = True
regEx.Global = True
msCCNumber = regEx.Replace(CCNumber, "")

Dim CurrentYear: CurrentYear = Year(Now())
If ((Len(msCCNumber) = 0) Or (CCExpMonth < 1) Or (CCExpMonth 12) Or (CCExpYear < CurrentYear) Or (CCExpYear (CurrentYear + 10))) Then Exit Function
msCCExpMonth = CCExpMonth
msCCExpYear = CCExpYear

Select Case msCCType
Case CARD_TYPE_MC:
Dim ValidFormat: ValidFormat = "^5[1-5][0-9]{14}$"

Case CARD_TYPE_VS:
ValidFormat = "^4[0-9]{12}([0-9]{3})?$"

Case CARD_TYPE_AX:
ValidFormat = "^3[47][0-9]{13}$"

Case CARD_TYPE_DC:
ValidFormat = "^3(0[0-5]|[68][0-9])[0-9]{11}$"

Case CARD_TYPE_DS:
ValidFormat = "^6011[0-9]{12}$"

Case CARD_TYPE_JC:
ValidFormat = "^(3[0-9]{4}|2131|1800)[0-9]{11}$"

Case Else:
ValidFormat = False
End Select
regEx.Pattern = ValidFormat
ValidateCreditCard = regEx.Test(msCCNumber) And Mod10(msCCNumber)

End Function%>

---
This posting is provided "AS IS" with no warranties and no guarantees either express or implied.

Stefan Berglund
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles