To be honest, i am a beginner and I need this for my sch proj. Here is somewhat on how our NRIC is based on. Singapore NRIC.
Also not sure if this link is absolutely correct. Anyone have done this validation before?
Thanks alot for helping
To be honest, i am a beginner and I need this for my sch proj. Here is somewhat on how our NRIC is based on. Singapore NRIC.
Also not sure if this link is absolutely correct. Anyone have done this validation before?
Thanks alot for helping
Sounds like a regex job, I can write one if you post definitive examples of what you are validating
Sent from my XT910 using Tapatalk 2
Would be somewhat hard to do with RegEx, as it's not entirely "regular". Here's a notepad written function, try it out, have not tested it.
Private Function CalculateNRICCheckDigit(ByVal NRICNumber As String) As String
Dim arrWeight() As Integer = {2,7,6,5,4,3,2}
Dim arrChkDigit() As String = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "Z", "J"}
For intDigit = 1 To 7
intNRICDigit = CInt(NRICNumber.SubString(intDigit, 1))
Sum += intNRICDigit * arrWeight(intDigit - 1)
Next
ChkDigit = 11 - (Sum \ 11)
CalculateNRICCheckDigit = arrChkDigit(ChkDigit - 1)
End Function
Thanks Lotok and Herman for replying. Teach me how to increase your reps later. What i want is checking based on Singapore NRIC the algorithm here. Meaning length will be 9. The first char must be alpha S. followed by 7 digits. And the last an alphabet. However the last alphabet cannot be any alphabet but based on the algo of the link given. for example 8840672 will return 'I' or 'i' as last alpha while 8930001 will return 'J' or 'j'. If not clear i can explain again. Thanks so much, i in need for solution
If you would care to look at the example I posted it does exactly that. Give it S1234567 and it will return the last character.
Herma it says intNricDigit, Sum and ChkDIgit is not declared. mind telling me what type should i declare for each?
I misunderstood the requirement, you are quite right a regex wont work. I thought you were validating the number structure, not checking if the number matched an algorithm.
I will leave it to herman since he seems to understand the maths involved.
Here, I took 5 minutes and rewrote it in IDE, it's tested...
Private Function CalculateNRICCheckDigit(ByVal strNRICNumber As String) As Char
Dim arrWeight() As Integer = {2, 7, 6, 5, 4, 3, 2} ' 0-6
Dim arrChkDigit() As Char = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "Z", "J"} ' 0-10
Dim intSum As Integer
CalculateNRICCheckDigit = Nothing
If Not strNRICNumber.Length = 8 _
Or Not strNRICNumber.Substring(0, 1).ToUpper = "S" _
Or Not IsNumeric(strNRICNumber.Substring(1)) Then _
Exit Function
For intDigit As Integer = 1 To 7
intSum += CInt(strNRICNumber.Substring(intDigit, 1)) * arrWeight(intDigit - 1)
Next
CalculateNRICCheckDigit = arrChkDigit(10 - (intSum Mod 11))
End Function
Last edited by Herman; 06-29-2012 at 7:03 PM.
Bookmarks