hi guys,

can i ask how do i check for validation for my username field if last letter must be an alphabet?

the username is in the format of 7digit + alphabet i had successfully check for the first 7 digit using isnumeric substring 0,7 but i have no idea how to check my 8th letter to be alphabet a-z etc

thx man!

I am thinking your approach is not completely robust. Without checking I imagine the 123.45 will return true to isnumeric which I imagine you don't want.

Personally, I am not a fan of masked text boxes because they are not that user friendly but it is a quick and easy way to achieve what you want. Use a mask of "0000000A" and set the ASCII only property to true.

If you want to test the 8th character to see if it is a letter here is the code

Dim aChar As String
        aChar = UCase$(Mid$(TextBox3.Text, 8, 1))
        If aChar >= "A" And aChar <= "Z" Then
            Label4.Text = "The 8th char is a letter"
        Else
            Label4.Text = "The 8th char is not a letter"
        End If

Edited 6 Years Ago by ChrisPadgham: additon to answer

to validate just use this
dim hold as string

hold=strings.right(text1.text,1)

if isnumeric(hold)=false then

msgbox"its a character"
else
msgbox"its a number"

end if

thx guys,

both code works.
i can check last letter for alphabet now :D

and yes the decimal as you guess still true ><
i need to think how to fix that ><'''

cheers

to validate just use this
dim hold as string

hold=strings.right(text1.text,1)

if isnumeric(hold)=false then

msgbox"its a character"
else
msgbox"its a number"

end if

this will not check for a-z, they could enter a !, @, # etc and it would still say it is true. and you are assuming the string entered is exactly 8 characters long.

Edited 6 Years Ago by ChrisPadgham: n/a

yes, ur right again :) shit. i have to use yr code then ^^ lol, i never thought of testing with !@#$ etc

this will not check for a-z, they could enter a !, @, # etc and it would still say it is true. and you are assuming the string entered is exactly 8 characters long.

yes, ur right again :) shit. i have to use yr code then ^^ lol, i never thought of testing with !@#$ etc

This will correctly test to make sure you only have letters - no numbers or symbols allowed.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim hold As String
        hold = Strings.Right(textbox1.Text.ToUpper, 1)
        If hold Like "[A-Z]" Then ' [!A-Z] would be use for "not in this set"
            MsgBox("its a letter")
        Else
            MsgBox("its not a letter")
        End If
    End Sub

I knew about this from creating a "hangman" game for may daughter - I had to make sure she didn't trick me by using numbers or hyphens! (Chris might think this is new-fangled!)

And Chris is right - you should also validate that the correct number of characters are entered, and be careful of upper and lower case!

This question has already been answered. Start a new discussion instead.