We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Validation text cointains character and number in textbox

Hi all,

How can i validate a text in text box?
I need to check that text length is 7 and first four characters is contain "ABCD" and last three characters must contain numbers.
e.g : ABCD123

Thank you.

2
Contributors
4
Replies
1 Hour
Discussion Span
1 Year Ago
Last Updated
8
Views
Question
Answered
Sturdy
Light Poster
39 posts since Mar 2011
Reputation Points: 28
Solved Threads: 1
Skill Endorsements: 0

You can use Mid() , Left() or Right() function to get The first four characters and the last 3 characters and Use Len() for the length of text.

Jx_Man
Senior Poster
3,553 posts since Nov 2007
Reputation Points: 1,500
Solved Threads: 531
Skill Endorsements: 65

You can use Mid() , Left() or Right() function to get The first four characters and the last 3 characters and Use Len() for the length of text.

Thank you for the suggestion.
This how far i'm doing. But i don't know how to check if last 3 character is number?

Private Sub Command1_Click()
Dim First4Char, Last3Char As String
First4Char = Mid(Text1.Text, 1, 4)
Last3Char = Mid(Text1.Text, 5, 7)
If Len(Text1.Text) <= 7 Then
    If First4Char <> "ABCD" Then
        MsgBox "Wrong"
    End If
    ' How i can check if last 3 char is numbers?
    
End If
End Sub
Sturdy
Light Poster
39 posts since Mar 2011
Reputation Points: 28
Solved Threads: 1
Skill Endorsements: 0

This how far i'm doing. But i don't know how to check if last 3 character is number?

Use IsNumeric() function :

Private Sub Command1_Click()
Dim First4Char, Last3Char As String
First4Char = Mid(Text1.Text, 1, 4)
Last3Char = Mid(Text1.Text, 5, 7)
If Len(Text1.Text) <= 7 Then
    If First4Char <> "ABCD" Then
        MsgBox "Wrong"
    Else
        If Not IsNumeric(Last3Char) Then
            MsgBox "Wrong Input"
        Else
            ' Action if text is accepted
        End If
    End If
End If
End Sub
Jx_Man
Senior Poster
3,553 posts since Nov 2007
Reputation Points: 1,500
Solved Threads: 531
Skill Endorsements: 65

Use IsNumeric() function :

Private Sub Command1_Click()
Dim First4Char, Last3Char As String
First4Char = Mid(Text1.Text, 1, 4)
Last3Char = Mid(Text1.Text, 5, 7)
If Len(Text1.Text) <= 7 Then
    If First4Char <> "ABCD" Then
        MsgBox "Wrong"
    Else
        If Not IsNumeric(Last3Char) Then
            MsgBox "Wrong Input"
        Else
            ' Action if text is accepted
        End If
    End If
End If
End Sub

Thank you sir. It worked very nice.

Sturdy
Light Poster
39 posts since Mar 2011
Reputation Points: 28
Solved Threads: 1
Skill Endorsements: 0
Question Answered as of 1 Year Ago by Jx_Man

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page generated in 0.0856 seconds using 2.65MB