amitnigamz
New Member
- Joined
- Apr 18, 2020
- Messages
- 1
- Office Version
- 2016
- Platform
- Windows
hello all !!
i want to create a function to check a string of lenght 10. Here first 5 character only alphabet i.e A-Z or a-z and then 4 character only digit i.e 0-9 and the last character must be only
alphabet i.e A-Z or a-z . I tried to solved it but could'd
# code
Function PAN_CHECK(pan_no As Variant) As Variant
'Dim pan_no As Variant
Dim pan_size As Integer
Dim input_string As Variant
Dim split_aplha, split_aplha1 As String
Dim alpha_len As Integer
input_string = pan_no
pan_size = Len(Trim(pan_no))
If input_string = "" Then
PAN_CHECK = "BLANK"
ElseIf pan_size = 10 Then
' CHECK FOR FIRST 5 WORDS ARE APLHABET
split_alpha = Left(input_string, 5)
'alpha_len = Len(split_alpha)
For alpha_len = 1 To Len(split_alpha)
If Left(slpit_alpha, alpha_len) = "" Then
PAN_CHECK = "WRONG"
ElseIf Asc(Left(slpit_alpha, alpha_len)) < 65 Or Asc(Left(slpit_alpha, alpha_len)) > 90 Then PAN_CHECK = "WRONG"
ElseIf Asc(Left(slpit_alpha, alpha_len)) < 97 Or Asc(Left(slpit_alpha, alpha_len)) > 122 Then PAN_CHECK = "WRONG"
Else
PAN_CHECK = "CORRECT"
End If
Next alpha_len
'CHECK FOR MID 4 WORDS ARE NUMBER
split_alpha = Mid(input_string, 6, 4)
For alpha_len = 1 To Len(split_alpha
If Left(slpit_alpha, alpha_len) = "" Then
PAN_CHECK = "WRONG"
ElseIf Asc(Left(split_alpha, split_len)) < 48 Then PAN_CHECK = "WRONG"
ElseIf Asc(Left(split_alpha, split_len)) > 57 Then PAN_CHECK = "WRONG"
Else
PAN_CHECK = "CORRECT"
End If
Next alpha_len
'CHECK FOR LAST 1 WORDS IS ALPHABET
split_alpha = Right(input_string, 1)
If Left(slpit_alpha, alpha_len) = "" Then
PAN_CHECK = "WRONG"
ElseIf Asc(Left(slpit_alpha, alpha_len)) < 65 Or Asc(Left(slpit_alpha, alpha_len)) > 90 Then PAN_CHECK = "WRONG"
ElseIf Asc(Left(slpit_alpha, alpha_len)) < 97 Or Asc(Left(slpit_alpha, alpha_len)) > 122 Then PAN_CHECK = "WRONG
Else
PAN_CHECK = "CORRECT"
End If
Else
PAN_CHECK = "WRONG"
End If
End Function
#code
i want to create a function to check a string of lenght 10. Here first 5 character only alphabet i.e A-Z or a-z and then 4 character only digit i.e 0-9 and the last character must be only
alphabet i.e A-Z or a-z . I tried to solved it but could'd
# code
Function PAN_CHECK(pan_no As Variant) As Variant
'Dim pan_no As Variant
Dim pan_size As Integer
Dim input_string As Variant
Dim split_aplha, split_aplha1 As String
Dim alpha_len As Integer
input_string = pan_no
pan_size = Len(Trim(pan_no))
If input_string = "" Then
PAN_CHECK = "BLANK"
ElseIf pan_size = 10 Then
' CHECK FOR FIRST 5 WORDS ARE APLHABET
split_alpha = Left(input_string, 5)
'alpha_len = Len(split_alpha)
For alpha_len = 1 To Len(split_alpha)
If Left(slpit_alpha, alpha_len) = "" Then
PAN_CHECK = "WRONG"
ElseIf Asc(Left(slpit_alpha, alpha_len)) < 65 Or Asc(Left(slpit_alpha, alpha_len)) > 90 Then PAN_CHECK = "WRONG"
ElseIf Asc(Left(slpit_alpha, alpha_len)) < 97 Or Asc(Left(slpit_alpha, alpha_len)) > 122 Then PAN_CHECK = "WRONG"
Else
PAN_CHECK = "CORRECT"
End If
Next alpha_len
'CHECK FOR MID 4 WORDS ARE NUMBER
split_alpha = Mid(input_string, 6, 4)
For alpha_len = 1 To Len(split_alpha
If Left(slpit_alpha, alpha_len) = "" Then
PAN_CHECK = "WRONG"
ElseIf Asc(Left(split_alpha, split_len)) < 48 Then PAN_CHECK = "WRONG"
ElseIf Asc(Left(split_alpha, split_len)) > 57 Then PAN_CHECK = "WRONG"
Else
PAN_CHECK = "CORRECT"
End If
Next alpha_len
'CHECK FOR LAST 1 WORDS IS ALPHABET
split_alpha = Right(input_string, 1)
If Left(slpit_alpha, alpha_len) = "" Then
PAN_CHECK = "WRONG"
ElseIf Asc(Left(slpit_alpha, alpha_len)) < 65 Or Asc(Left(slpit_alpha, alpha_len)) > 90 Then PAN_CHECK = "WRONG"
ElseIf Asc(Left(slpit_alpha, alpha_len)) < 97 Or Asc(Left(slpit_alpha, alpha_len)) > 122 Then PAN_CHECK = "WRONG
Else
PAN_CHECK = "CORRECT"
End If
Else
PAN_CHECK = "WRONG"
End If
End Function
#code