Hello, I'm currently creating an application in VB.Net. I have used the IsNumeric function for registering the name but the function only work if I enter only Numeric. If I enter Char + Numeric it doesn't provide any error message. For example if I key in James007, the data are still added into the DB.Hope someone could rectify the problem for me. Thank you.

If (IsNumeric(txtName.Text)) Then
                MsgBox("Numeric Characters are not allowed in Name!", vbCritical + vbOKOnly, "Invalid")
                txtName.Text = ""
                txtName.Focus()
End If

Try following code:

If txtName.Text.IndexOfAny("0123456789") <> -1 Then
            MsgBox("Invalid name")
        End If

Does your code show the message box when you use "James007" as an input?

If your code is in a procedure, you should exit procedure or do something to not to execute DB insert code

If (IsNumeric(TextBox1.Text)) Then
  MsgBox("Numeric Characters are not allowed in Name!", MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly, "Invalid")
  TextBox1.Text = ""
  TextBox1.Focus()
  Exit Sub ' <- Exit if this is a procedure
End If

Try following code:

If txtName.Text.IndexOfAny("0123456789") <> -1 Then
            MsgBox("Invalid name")
        End If

Thank you alot..This stuff works fine..:D

Thank and go ahead.

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.