Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello,

I've been asked to validate the content of a text box to make sure it's only alphanumeric.

Now I have 2 question on this from you experts:

 

1. alphanumeric value needs to start with alpha or it can start with numbers also?

 

2. I wrote the following code to test my entry but it's somewhere wrong I cannot understand! How can I go through each character to make sure it's alphanumeric?

 

For MyLoop As Integer = 0 To PasswordTextBoxX.Text.Length - 1
   If PasswordTextBoxX.Text.Substring(MyLoop, 1) <= "a" Or PasswordTextBoxX.Text.Substring(MyLoop, 1) >= "z" And _
      PasswordTextBoxX.Text.Substring(MyLoop, 1) <= "A" Or PasswordTextBoxX.Text.Substring(MyLoop, 1) >= "Z" And _
      PasswordTextBoxX.Text.Substring(MyLoop, 1) <= "0" Or PasswordTextBoxX.Text.Substring(MyLoop, 1) >= "9" Then
       MsgBox("invalid")
   End If
Next

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...