Hi,
First spilt pan numbers and pass the spilt values for each functions for verify it, Here all function must return false, otherwise PAN number is incorrect.
In fourth position i pass characters to check as "ABCFGHLJPT", bcz u mention 4 position must contain specific character.
Dim st As String = "BKLPA9891H"
Dim strfirst As String = st.Substring(0, 5)
Dim strmiddle As String = st.Substring(5, 4)
Dim strlast As String = st.Substring(9, 1)
Dim strpo4 As String = st.Substring(3, 1)
Dim chkchr As Boolean = IsCharAlphabet(strfirst)
Dim chkdigit As Boolean = IsNumber(strmiddle)
Dim chklastchr As Boolean = IsCharAlphabet(strlast)
Dim chkIsABCFGHLJPT As Boolean = IsABCFGHLJPT(strpo4)
If chkchr = True Or chkdigit = True Or chklastchr = True Or chkIsABCFGHLJPT = True Then
Dim strError = "PAN numbers need to have 5 characters followed by 4 numbers then a final character. Please check your entry and try again"
Else
Dim strSuccess = "PAN number accpected"
End If
Function to check spilt strings.
Function IsNumber(s As String) As Boolean
Dim strrtn As Boolean = False
For i = 0 To s.Length - 1
If Not System.Text.RegularExpressions.Regex.IsMatch(s(i), "^[0-9 ]+$") Then
strrtn = True
End If
Next
Return strrtn
End Function
Function IsCharAlphabet(s As String) As Boolean
Dim strrtn As Boolean = False
For i = 0 To s.Length - 1
If Not System.Text.RegularExpressions.Regex.IsMatch(s(i), "^[A-Z]+$") Then
strrtn = True
End If
Next
Return strrtn
End Function
Function IsABCFGHLJPT(s As String) As Boolean
Dim strrtn As Boolean = False
Dim chkChar As String = "ABCFGHLJPT"
For i = 0 To chkChar.Length - 1
If Not s.Contains(chkChar(i)) Then
strrtn = True
Else
strrtn = False
GoTo Reachhere
End If
Next
Reachhere:
Return strrtn
End Function
From your code, i updated case 5, bcz from 1 to 5 is alphabet, but in 5 position must be some specific alphabet, so it check passing char is alphabet and it must any one of this character "ABCFGHLJPT". So no need if codition.
Select Case Pos
Case 1 To 4
Test = TestForAlpha(Mid(PAN, Pos, 1))
Case 5
Test = TestForAlpha4(Mid(PAN, Pos, 1))
Case 6 To 9
Test = TestForNumeric(Mid(PAN, Pos, 1))
Case 10
Test = TestForAlpha(Mid(PAN, Pos, 1))
End Select
Thanks and Regards
Aravind.
Note: Pls accept answer is it useful to you. Happy Coding...