SIMIN Posted September 18, 2008 Posted September 18, 2008 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 Quote
Administrators PlausiblyDamp Posted September 18, 2008 Administrators Posted September 18, 2008 You could check each character using the Char.IsLetterOr Digit function, or a regular expression match could be used If Regex.Match(PasswordTextBoxX.Text, "^[a-zA-Z0-9]+$").Captures.Count > 0 Then 'is alphanumeric End If Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Leaders snarfblam Posted September 19, 2008 Leaders Posted September 19, 2008 If you want to see if a particular character is alphanumeric you can use the Char.IsLetterOrDigit(). Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.