Results 1 to 10 of 10
Like Tree1Likes
  • 1 Post By Herman

Thread: validate Singapore NRIC/FIN number from user input

  1. #1
    10e5x is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Jun 2012
    Posts
    14
    Reputation
    13

    validate Singapore NRIC/FIN number from user input

    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

  2. #2
    Lotok is offline VB.NET Forum Genius
    .NET Framework
    .NET 4.0
    Join Date
    Jan 2012
    Location
    Scotland
    Posts
    193
    Reputation
    22
    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

  3. #3
    Herman is offline VB.NET Forum Miyagee
    .NET Framework
    .NET 4.0
    Join Date
    Oct 2011
    Location
    Montreal, QC, CA
    Posts
    448
    Reputation
    346
    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
    10e5x likes this.

  4. #4
    10e5x is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Jun 2012
    Posts
    14
    Reputation
    13
    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

  5. #5
    Herman is offline VB.NET Forum Miyagee
    .NET Framework
    .NET 4.0
    Join Date
    Oct 2011
    Location
    Montreal, QC, CA
    Posts
    448
    Reputation
    346
    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.

  6. #6
    10e5x is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Jun 2012
    Posts
    14
    Reputation
    13
    Quote Originally Posted by Herman View Post
    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.
    i tried but it gives me error, maybe its my coding too noob. nvm i will try till can. let u know again thanks Herman

  7. #7
    10e5x is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Jun 2012
    Posts
    14
    Reputation
    13
    Herma it says intNricDigit, Sum and ChkDIgit is not declared. mind telling me what type should i declare for each?

  8. #8
    Lotok is offline VB.NET Forum Genius
    .NET Framework
    .NET 4.0
    Join Date
    Jan 2012
    Location
    Scotland
    Posts
    193
    Reputation
    22
    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.

  9. #9
    Herman is offline VB.NET Forum Miyagee
    .NET Framework
    .NET 4.0
    Join Date
    Oct 2011
    Location
    Montreal, QC, CA
    Posts
    448
    Reputation
    346
    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.

  10. #10
    10e5x is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Jun 2012
    Posts
    14
    Reputation
    13
    Quote Originally Posted by Herman View Post
    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
    Thanks Herman it work it works. Thanks so much. I to mark this as solve and rep u? Sry new to forum

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking