I have a 2 textbox
1 text box is empty .
text2 is multine true
second text box have some words.
text2 text Example :
"12345 is my number and 03451234567ddddsfsa
somethingis wrong034512345find 03451234567"
..............
i want to find 03451234567 11digit number in text box with first 3 or 4 numbers
i mean when we type 034 or 0345 in text1 and click command button then find 0345 in text box and select all numeric number means 03451234567 and add to a listbox.
Note: when find 0345 and check 11 digits or max . if find max to 11 digits so do not add
in listbox.

i hope every one can understand what we want to do .
simply i want to find 11 digit mobile numbers in text box with first 3 or 4 words.

Dani AI

Generated

As described, the goal is to extract exact 11-digit mobile numbers that begin with the user-entered 3‑ or 4‑digit prefix. As pointed out, regular expressions are the right tool — the missing piece for VB6 is how to build a VB6-friendly pattern that (a) uses the typed prefix, (b) enforces exactly 11 digits, and (c) ignores numbers that are part of longer digit runs. The sample below shows a simple CommandButton handler using the Microsoft VBScript RegExp object and returns only the numeric match (not surrounding characters).

' Project -> References: add "Microsoft VBScript Regular Expressions 5.5"
Private Sub Command1_Click()
    Dim re As RegExp, matches As MatchCollection, m As Match
    Dim prefix As String, expected As Long, number As String

    prefix = Trim(Text1.Text)
    If Len(prefix) < 3 Or Len(prefix) > 4 Or Not IsNumeric(prefix) Then
        MsgBox "Enter a 3- or 4-digit numeric prefix."
        Exit Sub
    End If

    expected = 11 - Len(prefix)
    Set re = New RegExp
    re.Pattern = "(^|[^\d])(" & prefix & "\d{" & expected & "})(?!\d)"
    re.Global = True

    Set matches = re.Execute(Text2.Text)
    For Each m In matches
        number = m.SubMatches(1)   ' submatch 0 = preceding char / start, submatch 1 = the 11-digit number
        If Not ItemExists(List1, number) Then List1.AddItem number
    Next
End Sub

Private Function ItemExists(lst As ListBox, val As String) As Boolean
    Dim i As Long
    For i = 0 To lst.ListCount - 1
        If lst.List(i) = val Then ItemExists = True: Exit Function
    Next
End Function

Notes and troubleshooting:

  • Use the RegExp reference (VBScript RegExp 5.5) or the object won't be available.
  • The pattern ensures exactly 11 digits by computing the remaining count from the prefix and uses a negative lookahead so a matched 11-digit string is not followed by another digit. The (^|[^\d]) prefix prevents accepting a match that is already part of a longer digit sequence.
  • If numbers may contain separators (spaces, dashes), adjust the pattern to allow optional separators and then strip them before adding to the listbox.
  • If matches are missing when digits are glued to letters, this approach still works because it checks for non-digit boundaries rather than word boundaries (word boundaries can fail between letters and digits).

This can be done easily with regular expressions. The pattern

"\d{11}"

Matches any 11 digit sequence. The trick, in your case, is to replace the numeric parameter with the number of digits remaining. If you are looking for an 11 digit number beginning with 034 then you create the pattern

"034\d{8}"    

I can't try this for you under VB6 (I don't have it installed), however, here is a to a Microsoft article on how to do it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.