Hello.

I have 200 dynamic textboxes.

I am trying to limit the user input to exactly 5 characters ( not more, not less ), and numeric only.

I have been trying this :
Code:
   Private Function txtValid()

        Dim str As String

        For Each txt As TextBox In Panel1.Controls
            str = txt.Text

            If str.Length = 5 OrElse str = "" Then
                If txt.Text.IndexOfAny(charactersAllowed) > -1 Then
                    txt.Text = lastText

                    Return True
                Else
                    lastText = txt.Text

                    Return False
                End If
            Else
                Return False
            End If


        Next


    End Function
Call it like :
Code:
    Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
        If txtValid() Then
            dgSummary.PreferredColumnWidth = 240
            dgSummary.PreferredRowHeight = 25

            dt = GetProductSummary()
            dgSummary.DataSource = dt

            CopyAll(dgSummary)

            btnExecute.Enabled = True

        Else
            MessageBox.Show("Please enter FIVE ( 5 ) digits ( NUMBERS ) only!")
        End If
But it always shows the last messagebox. Not all 200 textboxes will be filled in, so I suspect that it may have something to do with that, but I just need to stop the user from entering alphabetical characters, and the entered field must have a length of 5

Can anyone help?