متد VB.Net جهت بررسی اعتبار کد ملی
رقم آخر در کد ملی برای کنترل صحت استفاده می شود و بوسیله تابع زیر می توان اعتبار آن را سنجید :
Private Function IsValidMelliCode(ByVal melliCode As String)
Try
melliCode = melliCode.Replace("-", "")
Dim pos As Integer = 10
Dim sum As Integer = 0
For i = 0 To 8
sum += Integer.Parse(melliCode.ToCharArray()(i).ToString()) * pos
pos = pos - 1
Next i
Dim remind As Integer = sum Mod 11
Dim controlNum As Integer = Integer.Parse(melliCode.ToCharArray()(9))
If remind <= 2 Then
If controlNum = remind Then
Return True
Else
Return False
End If
Else
If (11 - remind) = controlNum Then
Return True
Else
Return False
End If
End If
Catch ex As Exception
Throw ex
End Try
End Function
Try
melliCode = melliCode.Replace("-", "")
Dim pos As Integer = 10
Dim sum As Integer = 0
For i = 0 To 8
sum += Integer.Parse(melliCode.ToCharArray()(i).ToString()) * pos
pos = pos - 1
Next i
Dim remind As Integer = sum Mod 11
Dim controlNum As Integer = Integer.Parse(melliCode.ToCharArray()(9))
If remind <= 2 Then
If controlNum = remind Then
Return True
Else
Return False
End If
Else
If (11 - remind) = controlNum Then
Return True
Else
Return False
End If
End If
Catch ex As Exception
Throw ex
End Try
End Function
+ نوشته شده در یکشنبه بیست و سوم مهر ۱۳۹۱ ساعت 12:5 توسط صادق قنبری شوهانی
|
در این وبلاگ طراحی وب سایت بصورت عملی و کاربردی آموزش داده می شود .