Šaljem ti kod za proveru JMBG. Kako se u to polje ponekad upisuje PIB, ako je reč o firmi, možeš da kombinuješ sa funkcijom za proveru PIB-a:
Code:
Function Proveri_JMBG(JMBG As String) As String
'
' funkcija vraca tekst sa opisom ispravnosti JMBG
'
' upotreba na radnom listu: =Proveri_JMBG(adr)
' init promenljive
Dim duzina As Integer, zbir As Integer
Dim cifra(1 To 13) As Integer, i As Integer
Dim dan As Integer, mesec As Integer, Godina As String
' init konstante; izmeniti po volji
Const ERR_dan = "GREŠKA: podatak o datumu neispravan!"
Const ERR_mesec = "GREŠKA: podatak o mesecu neispravan!"
Const ERR_godina = "GREŠKA: podatak o godini neispravan!"
Const ERR_duzina = "GREŠKA: dužina različita od 13!"
Const ERR_kont = "GREŠKA: neispravan kontrolni broj ili datum!"
Const OK_JMBG = "-1"
' preuzimanje ulaznih vrednosti
duzina = Len(JMBG)
dan = Int(Left(JMBG, 2))
mesec = Int(Mid$(JMBG, 3, 2))
Godina = Mid$(JMBG, 5, 3)
' provera dužine JMBG
If (duzina <> 13) Then
Proveri_JMBG = ERR_duzina
Exit Function
End If
' provera datuma
If dan < 1 Then
Proveri_JMBG = ERR_dan
Exit Function
End If
' provera meseca i dana u mesecu
Select Case mesec
Case 1, 3, 5, 7, 8, 10, 12
If dan > 31 Then
Proveri_JMBG = ERR_dan
Exit Function
End If
Case 4, 6, 9, 11
If dan > 30 Then
Proveri_JMBG = ERR_dan
Exit Function
End If
Case 2
If ((Godina Mod 4 = 0) And dan > 29) Or _
((Godina Mod 4 <> 0) And dan > 28) Then
Proveri_JMBG = ERR_dan
Exit Function
End If
Case Else
Proveri_JMBG = ERR_mesec
Exit Function
End Select
' provera godine: ispravne su od 1899 do teku?e godine
If (Godina > Right(Str(Year(Now)), 3)) And (Godina < "899") Then
Proveri_JMBG = ERR_godina
Exit Function
End If
' provera kontrolnog broja
For i = 1 To 13
cifra(i) = Int(Mid$(JMBG, i, 1))
Next i
zbir = cifra(13) + cifra(1) * 7 + cifra(2) * 6 + cifra(3) * 5 + cifra(4) * 4
zbir = zbir + cifra(5) * 3 + cifra(6) * 2 + cifra(7) * 7 + cifra(8) * 6
zbir = zbir + cifra(9) * 5 + cifra(10) * 4 + cifra(11) * 3 + cifra(12) * 2
If (zbir Mod 11) <> 0 Then
Proveri_JMBG = ERR_kont
Else
Proveri_JMBG = OK_JMBG
End If
End Function
Public Function ProveriPIB(PIB As String)
Dim c0 As Integer
Dim c1 As Integer
Dim c2 As Integer
Dim c3 As Integer
Dim c4 As Integer
Dim c5 As Integer
Dim c6 As Integer
Dim c7 As Integer
Dim c8 As Integer
Dim zadnji As String
zadnji = Right(PIB, 1)
PIB = Left(PIB, 8)
If Len(PIB) <> 8 Then
ProveriPIB = 1
Else
c8 = (CInt(Mid(PIB, 1, 1)) + 10) Mod 10
If c8 = 0 Then
c8 = 10
End If
c8 = (c8 * 2) Mod 11
c7 = (CInt(Mid(PIB, 2, 1)) + c8) Mod 10
If c7 = 0 Then
c7 = 10
End If
c7 = (c7 * 2) Mod 11
c6 = (CInt(Mid(PIB, 3, 1)) + c7) Mod 10
If c6 = 0 Then
c6 = 10
End If
c6 = (c6 * 2) Mod 11
c5 = (CInt(Mid(PIB, 4, 1)) + c6) Mod 10
If c5 = 0 Then
c5 = 10
End If
c5 = (c5 * 2) Mod 11
c4 = (CInt(Mid(PIB, 5, 1)) + c5) Mod 10
If c4 = 0 Then
c4 = 10
End If
c4 = (c4 * 2) Mod 11
c3 = (CInt(Mid(PIB, 6, 1)) + c4) Mod 10
If c3 = 0 Then
c3 = 10
End If
c3 = (c3 * 2) Mod 11
c2 = (CInt(Mid(PIB, 7, 1)) + c3) Mod 10
If c2 = 0 Then
c2 = 10
End If
c2 = (c2 * 2) Mod 11
c1 = (CInt(Mid(PIB, 8, 1)) + c2) Mod 10
If c1 = 0 Then
c1 = 10
End If
c1 = (c1 * 2) Mod 11
c0 = (11 - c1) Mod 10
If c0 <> zadnji Then
ProveriPIB = 1
Else
ProveriPIB = 0
End If
'return(pib || to_char(c0));
End If
End Function