如果可能,我想要一些帮助代码。
在荷兰,我们使用BSN号码作为个人身份证明。这是基于所谓的11-proef验证。但是,系统也允许添加外部标识。
它应该验证下一个例子: BE12345678910(比利时有11个数字,但未以相同方式验证)因此应始终返回true。 NL123456789(格式正确,应使用代码验证.123456789(格式正确,因此应使用相同的代码验证)
代码下方: 只验证123456789的那个:
Public Function ValidateBSN(bsnNr As String, ByRef errResult As Integer, Optional MaxLength As Integer = 9) As Boolean
If String.IsNullOrEmpty(bsnNr) Then
Return True
End If
Dim Length = bsnNr.Length
If bsnNr.StartsWith("NL") Or Length = 9 Then
Dim BSN As String = bsnNr.Replace("NL", "")
Length = BSN.Length
If MaxLength = Length Then
Try
Dim _BSN As Int64 = Convert.ToInt64(BSN)
Return True
Catch ex As Exception
Return False
End Try
Else
Return False
End If
Else
errResult = -1
Dim param(0) As ErrorParam
param(0) = New ErrorParam("BSN onjuist", "Voer een geldige BSN in.</br> Huidige waarde :<B> " + bsnNr.ToString() + "</b>")
RaiseError("BSN onjuist", param)
Return True
End If
End Function
11 pef:
Public Function CheckBSN(bsnNr As String) As Boolean
'In our case BSN may be empty...
If String.IsNullOrEmpty(bsnNr) Then
Return True
End If
' A BSN consists of 9 characters ...
If cleanBsnNr.Length <> 9 Then
Return False
End If
' ... all being numeric and not resulting in a 0 when converted to a number ...
Dim l As Long
If Not Long.TryParse(cleanBsnNr, l) Then
Return False
ElseIf l = 0 Then
Return False
End If
' ... the number must be validatable to the so-called 11-proof ...
Dim total As Long = 0
For i As Integer = 1 To 9
' 11-proof voor BSN's: (9*A + 8*B + 7*C + 6*D + 5*E + 4*F + 3*G + 2*H + (-1*I)) % 11 == 0
Dim number As Integer = Convert.ToInt32(cleanBsnNr(i - 1).ToString())
Dim multiplier As Integer = 10 - i
If i = 9 Then
multiplier = -1 * multiplier
End If
total += number * multiplier
Next
' ... not result in a 0 when dividing by 11 ...
If total = 0 Then
Return False
End If
' ... and not have a modulo when dividing by 11.
Return total Mod 11 = 0
End Function
我在11-proef的“我们的情况下BSN可能是空的”上方添加了此代码。
Dim cleanBsnNr As String = Mid(bsnNr, 3, 9)
确实验证了NL123456789,但如果激活,则验证123456789不再有效。
输入国家代码的原因是我们可以快速识别个人身份号码所在的国家/地区。