Function NIRvalide(NIR$) As Boolean
'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤'
'¤ ¤'
'¤ Ajouter la référence à la bibliothèque Microsoft VBScript Regular Expressions 5.5 au projet ! ¤'
'¤ ¤'
'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤'
Dim i&, k#, t$, RgEx As RegExp
If Len(NIR) = 13 Or Len(NIR) = 15 Then
For i = 1 To 13
t = Mid$(NIR, i, 1)
Select Case t
Case "0" To "9": k = k * 10 + CInt(t)
Case "A", "B": k = k * 10 + 64 - Asc(t)
End Select
Next
t = Right$(197 + Round(Int(k / 97) * 97, 0) - k, 2)
Set RgEx = New RegExp
With RgEx
.IgnoreCase = False
.Pattern = "^[1-9]{1}[0-9]{4}([0-9]{2}|(2[A-B]{1}))[0-9]{3}((00[1-9]|[0-9][1-9][0-9]|[1-9][0-9]{2})|(00[1-9]|[0-9][1-9][0-9]|[1-9][0-9]{2})" & t & ")$"
NIRvalide = .Test(NIR)
End With
Set RgEx = Nothing
End If
End Function