Vérification de divers code (INSEE, RIB/RIP, IBAN, ...)
Publié : lun. 23/mars/2020 17:45
Bonjour,
Voila un petit Module qui permet de faire des vérification de validité de certain code de la vie de tout les jours (comme INSEE, CMC7, RIB/RIP, IBAN, ...).
A vous de voir si cela peut, vous être utile.
Cordialement,
GallyHC
Voila un petit Module qui permet de faire des vérification de validité de certain code de la vie de tout les jours (comme INSEE, CMC7, RIB/RIP, IBAN, ...).
Code : Tout sélectionner
; ****************************************************************************
; ****************************************************************************
DisableASM
CompilerIf #PB_Compiler_EnableExplicit
EnableExplicit
CompilerEndIf
; ****************************************************************************
; ****************************************************************************
DeclareModule validateCheksumFR
Declare.b isValidSIREN (number.s)
Declare.b isValidSIRET (number.s)
Declare.b isValidINSEE (number.s, ikey.l = -1)
Declare.b isValidRIB (number.s, ikey.l = -1)
Declare.b isValidBankAccount (number.s)
Declare.b isValidCreditCard (number.s)
Declare.b isValidCMC7 (number.s, ikey.l = -1)
EndDeclareModule
;
;
;
Module validateCheksumFR
;
;
;
DisableASM
CompilerIf #PB_Compiler_EnableExplicit
EnableExplicit
CompilerEndIf
; METHODE DE CALCUL DU DOUBLE D'UNE VALEUR AVEC ADDITION.
;
; @author GallyHomeCorp
; @param value
; @return
Procedure.l calculMultiByTwo(value)
Define.l i
Define.s stemp
If value > 0
value * 2
While value > 9
stemp = Str(value)
value = 0
For i=1 To Len(stemp)
value + Val(Mid(stemp, i, 1))
Next i
Wend
ProcedureReturn value
EndIf
ProcedureReturn 0
EndProcedure
; ****************************************************************************
; ****************************************************************************
; METHODE DE VERIFICATION DE LA VALIDITE D'UN STRING.
;
; @author GallyHomeCorp
; @param string
; @param valid
; @return
Procedure.b isValidString(string.s, valid.s)
;
;
;
Define.l i = 0;
Define.b result = #True
If string <> #Null$
For i = 1 To Len(string)
If FindString(valid, Mid(string, i, 1), 1) = 0
result = #False
Break
EndIf
Next i
Else
result = #False
EndIf
;
ProcedureReturn result
EndProcedure
; ****************************************************************************
; ****************************************************************************
; METHODE DE VERIFICATION D'UN MATRICULE "SIREN".
;
; @author GallyHomeCorp
; @param number
; @return
Procedure.b isValidSIREN(number.s)
Define.l i, value
number = ReplaceString(LCase(number), " ", "")
If Len(number) > 9
number = Mid(number, 1, 9)
EndIf
If Len(number) = 9 And isValidString(number, "0123456789")
For i=1 To Len(number) Step 2
value + Val(Mid(number, i, 1))
If i + 1 <= Len(number)
value + calculMultiByTwo(Val(Mid(number, i + 1, 1)))
EndIf
Next i
ProcedureReturn Bool((value % 10) = 0)
EndIf
ProcedureReturn #False
EndProcedure
; METHODE DE VERIFICATION D'UN MATRICULE "SIRET".
;
; @author GallyHomeCorp
; @param number
; @return
Procedure.b isValidSIRET(number.s)
Define.l i, value
number = ReplaceString(LCase(number), " ", "")
If Len(number) > 14
number = Mid(number, 1, 14)
EndIf
If Len(number) = 14 And isValidString(number, "0123456789")
For i=1 To Len(number) Step 2
value + calculMultiByTwo(Val(Mid(number, i, 1)))
If i + 1 <= Len(number)
value + Val(Mid(number, i + 1, 1))
EndIf
Next i
ProcedureReturn Bool(((value % 10) = 0) And (Val(Mid(number, 10, 4)) > 0))
EndIf
ProcedureReturn #False
EndProcedure
; ****************************************************************************
; ****************************************************************************
; METHODE DE VERIFICATION D'UN MATRICULE "INSEE" (NUMERO SECURITE-SOCIAL).
;
; @author GallyHomeCorp
; @param number
; @param ikey
; @return
Procedure.b isValidINSEE(number.s, ikey.l = -1)
number = ReplaceString(LCase(number), " ", "")
number = ReplaceString(number, "2a", "19")
number = ReplaceString(number, "2b", "18")
If Len(number) = 15
ikey = Val(Mid(number, 14, 2))
number = Mid(number, 1, 13)
EndIf
If Len(number) = 13 And isValidString(number, "0123456789")
ProcedureReturn Bool(97 - (Val(number) % 97) = ikey)
EndIf
ProcedureReturn #False
EndProcedure
; METHODE DE VERIFICATION D'UN CODE "RIB/RIP".
;
; @author GallyHomeCorp
; @param number
; @param ikey
; @return
Procedure.b isValidRIB(number.s, ikey.l = -1)
number = ReplaceString(LCase(number), " ", "")
number = ReplaceString(number, "a", "1") : number = ReplaceString(number, "j", "1")
number = ReplaceString(number, "b", "2") : number = ReplaceString(number, "k", "2") : number = ReplaceString(number, "s", "2")
number = ReplaceString(number, "c", "3") : number = ReplaceString(number, "l", "3") : number = ReplaceString(number, "t", "3")
number = ReplaceString(number, "d", "4") : number = ReplaceString(number, "m", "4") : number = ReplaceString(number, "u", "4")
number = ReplaceString(number, "e", "5") : number = ReplaceString(number, "n", "5") : number = ReplaceString(number, "v", "5")
number = ReplaceString(number, "f", "6") : number = ReplaceString(number, "o", "6") : number = ReplaceString(number, "w", "6")
number = ReplaceString(number, "g", "7") : number = ReplaceString(number, "p", "7") : number = ReplaceString(number, "x", "7")
number = ReplaceString(number, "h", "8") : number = ReplaceString(number, "q", "8") : number = ReplaceString(number, "y", "8")
number = ReplaceString(number, "i", "9") : number = ReplaceString(number, "r", "9") : number = ReplaceString(number, "z", "9")
If Len(number) = 23
ikey = Val(Mid(number, 22, 2))
number = Mid(number, 1, 21)
EndIf
If Len(number) = 21 And isValidString(number, "0123456789")
ProcedureReturn Bool((97 - (89 * Val(Mid(number, 1, 5)) + 15 * Val(Mid(number, 6, 5)) + 3 * Val(Mid(number, 11, 11))) % 97) = ikey)
EndIf
ProcedureReturn #False
EndProcedure
; METHODE DE VERIFICATION D'UN CODE "IBAN".
;
; @author GallyHomeCorp
; @param number
; @return
Procedure.b isValidBankAccount(number.s)
Define.l i, ichecksum
Define.s bank, schecksum
number = ReplaceString(UCase(number), " ", "")
If number <> #Null$ And isValidString(number, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ")
bank = Mid(number, 5, Len(number) - 4) + Mid(number, 1, 4)
For i=1 To Len(bank)
If Asc(Mid(bank, i, 1)) >= 'A' And Asc(Mid(bank, i, 1)) <= 'Z'
schecksum + Str(Asc(Mid(bank, i, 1)) - 55)
Else
schecksum + Mid(bank, i, 1)
EndIf
Next i
ichecksum = Val(Mid(schecksum, 1, 1))
For i=2 To Len(schecksum)
ichecksum * 10
ichecksum + Val(Mid(schecksum, i, 1))
ichecksum = ichecksum % 97
Next i
ProcedureReturn Bool(ichecksum = 1)
EndIf
ProcedureReturn #False
EndProcedure
; METHODE DE VERIFICATION D'UN NUMERO DE CARTE BLEU.
;
; @author GallyHomeCorp
; @param number
; @return
Procedure.b isValidCreditCard(number.s)
Define.l i, value
number = ReplaceString(LCase(number), " ", "")
If Len(number) > 16
number = Mid(number, 1, 16)
EndIf
If Len(number) = 16 And isValidString(number, "0123456789")
For i=1 To Len(number) Step 2
value + calculMultiByTwo(Val(Mid(number, i, 1)))
If i + 1 <= Len(number)
value + Val(Mid(number, i + 1, 1))
EndIf
Next i
ProcedureReturn Bool((value % 10) = 0)
EndIf
ProcedureReturn #False
EndProcedure
; METHODE DE VERIFICATION D'UN CODE "CMC7".
;
; @author GallyHomeCorp
; @param number
; @param ikey
; @return
Procedure.b isValidCMC7(number.s, ikey.l = -1)
Define.i i, value
number = ReplaceString(number, " ", "")
If Len(number) = 33
ikey = Val(Mid(number, 32, 2))
number = Mid(number, 1, 31)
EndIf
If Len(number) = 31 And (ikey >= 0 And ikey < 97) And isValidString(number, "0123456789")
value = Val(Mid(number, 1, 8)) % 97
For i=0 To 2
value = Val(Str(value) + Mid(number, 9 + (i * 6), 6)) % 97
Next i
value = Val(Str(value) + Mid(number, 27, 6) + "00") % 97
ProcedureReturn Bool((97 - value) = ikey)
EndIf
ProcedureReturn #False
EndProcedure
EndModule
Cordialement,
GallyHC