Private Function VerifyCitizenID(citizenID As String) As Boolean
'ตรวจสอบว่าทุก ๆ ตัวอักษรเป็นตัวเลข
If citizenID.ToCharArray().All(Function(c) Char.IsNumber(c)) = False Then
Return False
End If
'ตรวจสอบว่าข้อมูลมีทั้งหมด 13 ตัวอักษร
If citizenID.Trim().Length <> 13 Then
Return False
End If
Dim sumValue As Integer = 0
For i As Integer = 0 To citizenID.Length - 2
sumValue += Integer.Parse(citizenID(i).ToString()) * (13 - i)
Next
Dim v As Integer = 11 - (sumValue Mod 11)
Return citizenID(12).ToString() = v.ToString()
End Function
'=======================================================
'Original code by Tungman with C#
'Service provided by Telerik (www.telerik.com)
'Conversion powered by NRefactory.
'Twitter: @telerik, @toddanglin
'Facebook: facebook.com/telerik
'=======================================================