Results 1 to 12 of 12

Thread: Checking a textbox to see if it is alphanumeric

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2010
    Posts
    3

    Checking a textbox to see if it is alphanumeric

    I want to make a password cache, and i want it to make sure it contains both Alphbetical and Numerical characters

    can anyone help me here

    I also want it to be atleast 6 characters long

  2. #2
    Fanatic Member
    Join Date
    Dec 2009
    Posts
    904

    Re: Checking a textbox to see if it is alphanumeric

    you need to use the regular expressions for this kind of checkings......

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2010
    Posts
    3

    Re: Checking a textbox to see if it is alphanumeric

    elaborate?

  4. #4
    Frenzied Member stateofidleness's Avatar
    Join Date
    Jan 2009
    Posts
    1,780

    Re: Checking a textbox to see if it is alphanumeric

    found this:

    vb Code:
    1. Public Shared Function IsAlphaNumeric(ByVal strToCheck As String) As Boolean
    2.     Dim pattern As Regex = New Regex("[^a-zA-Z0-9]")
    3.     Return Not pattern.IsMatch(strToCheck)
    4. End Function
    5.  
    6. 'You would pass it the .Text property of your textbox.
    7. IsAlphaNumeric(TextBox1.Text)

  5. #5
    Fanatic Member
    Join Date
    Dec 2009
    Posts
    904

    Re: Checking a textbox to see if it is alphanumeric

    Quote Originally Posted by stateofidleness View Post
    found this:

    vb Code:
    1. Public Shared Function IsAlphaNumeric(ByVal strToCheck As String) As Boolean
    2.     Dim pattern As Regex = New Regex("[^a-zA-Z0-9]")
    3.     Return Not pattern.IsMatch(strToCheck)
    4. End Function
    5.  
    6. 'You would pass it the .Text property of your textbox.
    7. IsAlphaNumeric(TextBox1.Text)
    and where is this condition as stated by the oz in #1

    I also want it to be atleast 6 characters long

  6. #6
    Frenzied Member stateofidleness's Avatar
    Join Date
    Jan 2009
    Posts
    1,780

    Re: Checking a textbox to see if it is alphanumeric

    oh well damn, let me do all the work for him:

    vb Code:
    1. Public Shared Function Isvalid(ByVal strToCheck As String) As Boolean
    2.      If strToCheck.Length >=6 Then
    3.           Dim pattern As Regex = New Regex("[^a-zA-Z0-9]")
    4.           Return pattern.IsMatch(strToCheck)
    5.      Else
    6.           Return False
    7.      End If
    8. End Function
    9.  
    10. 'You would pass it the .Text property of your textbox.
    11. IsValid(TextBox1.Text)

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Checking a textbox to see if it is alphanumeric

    Here's a method without using a Regex:
    vb.net Code:
    1. If myString.All(Function(ch) Char.IsLetterOrDigit(ch)) Then
    2.     'myString is alphanumeric.
    3. End If
    That uses LINQ so of course it requires at least .NET 3.5. The advantage of that is that it's not culture-specific, although that probably wouldn't be an issue in most cases anyway.

  8. #8

    Thread Starter
    New Member
    Join Date
    Apr 2010
    Posts
    3

    Re: Checking a textbox to see if it is alphanumeric

    what does Regex mean?

  9. #9
    Fanatic Member
    Join Date
    Dec 2009
    Posts
    595

    Re: Checking a textbox to see if it is alphanumeric

    regular expressions

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Checking a textbox to see if it is alphanumeric

    Quote Originally Posted by captainchopsticks07 View Post
    what does Regex mean?
    Looks like they fixed Google.

    http://www.google.com.au/search?q=re...ient=firefox-a

  11. #11

  12. #12
    New Member
    Join Date
    Apr 2014
    Posts
    1

    Re: Checking a textbox to see if it is alphanumeric

    Makes sure that it has at least either lower case alphabet or upper case alphabet and numbers else it deems it false...

    Code:
        Public Shared Function IsAlphabet(ByVal alpha As String) As Boolean
    
            Dim IsA As Boolean = False
    
            Try
                IsA = (Asc(alpha) >= 65 And Asc(alpha) <= 90) Or (Asc(alpha) >= 97 And Asc(alpha) <= 122)
            Catch ex As Exception
                IsA = False
            End Try
    
            Return IsA
    
        End Function
    
        Public Shared Function CheckIfAlphaNumeric(ByVal strInput As String) As Boolean
    
            Dim i As Integer
            Dim Chr As Char
    
            Dim boolNumeric As Boolean
            Dim boolAlphabet As Boolean
            Dim boolUnusedChars As Boolean
    
            boolNumeric = False
            boolAlphabet = False
            boolUnusedChars = False
    
            Dim arrBoolNumeric() As Boolean
            Dim arrBoolAlphbet() As Boolean
            Dim arrBoolUnusedChars() As Boolean
    
            ReDim arrBoolNumeric(0)
            arrBoolNumeric(0) = False
    
            ReDim arrBoolAlphbet(0)
            arrBoolAlphbet(0) = False
    
            ReDim arrBoolUnusedChars(0)
            arrBoolUnusedChars(0) = False
    
            If (strInput.Length = 0) Then
                Return False
            End If
    
            For i = 0 To strInput.Count - 1
    
                Chr = strInput.Chars(i)
    
                If (IsNumeric(Chr) = True) Or (IsAlphabet(Chr) = True) Then
    
                    If (IsNumeric(Chr) = True) Then
                        arrBoolNumeric(arrBoolNumeric.GetUpperBound(0)) = True
                        ReDim Preserve arrBoolNumeric(arrBoolNumeric.GetUpperBound(0) + 1)
                    End If
    
                    If (IsAlphabet(Chr) = True) Then
                        arrBoolAlphbet(arrBoolAlphbet.GetUpperBound(0)) = True
                        ReDim Preserve arrBoolAlphbet(arrBoolAlphbet.GetUpperBound(0) + 1)
                    End If
    
                Else
                    arrBoolUnusedChars(arrBoolUnusedChars.GetUpperBound(0)) = True
                    ReDim Preserve arrBoolUnusedChars(arrBoolUnusedChars.GetUpperBound(0) + 1)
                End If
    
            Next
    
            For i = 0 To arrBoolNumeric.GetUpperBound(0) - 1
                If (arrBoolNumeric(i) = False) Then
                    boolNumeric = False
                    Exit For
                Else
                    boolNumeric = True
                End If
            Next
    
            For i = 0 To arrBoolAlphbet.GetUpperBound(0) - 1
                If (arrBoolAlphbet(i) = False) Then
                    boolAlphabet = False
                    Exit For
                Else
                    boolAlphabet = True
                End If
            Next
    
            For i = 0 To arrBoolUnusedChars.GetUpperBound(0) - 1
                If (arrBoolUnusedChars(i) = True) Then
                    boolUnusedChars = True
                    Exit For
                Else
                    boolUnusedChars = True
                End If
            Next
    
            If (boolNumeric = False) Or _
                (boolAlphabet = False) Or _
                (boolUnusedChars = True) Then
    
                Return False
    
            Else
                Return True
            End If
    
        End Function

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width