Validate Alphanumeric Data

How to validate an alphanumeric data entry like a permanent account number (PAN) in a text-box on a user-from with vba quickly and easily. A PAN has the following characteristics:

First Three Digits Alphabetic series running from AAA to ZZZ
Fourth Digit Status (I.e. P For Personal, C for Corporate, F for Firm, H for Hindu Undivided Family Etc.)
Fifth Digit First character of assessee’s Last Name/ Surname
Next 4 Digits Sequential Number running from 0001 to 9999
Last Digit Alphabetic Check digit

Watch the video below:

Here’s the complete VBA code to validate an alphanumeric data entry in a text-box quickly<

Private Sub CommandButton1_Click()
If TextBox1.Text Like “[A-Za-z][A-Za-z][A-Za-z][ABFGHJLPTabfghjlpt][A-Za-z]####[A-Za-z]” Then
MsgBox “Valid PAN entry”
Range(“A2”) = TextBox1.Text
MsgBox “Invalid PAN entry”
Exit Sub
End If
End Sub