Results 1 to 7 of 7

Thread: testing if is alphanumeric?

  1. #1

    Thread Starter
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    how do i check if something is alpha numeric?

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Code:
    'in declarations
    option compare text
    'the code
    If Text like "[A-Z]" then...
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3

    Thread Starter
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    what wouldm happen if it was a number?

  4. #4
    Guest
    If it's like a number than you do this:

    Code:
    If Text Like "#" Then ...

  5. #5
    Guest
    try this function:

    Code:
    Public Function IsAlphaNumeric(ByVal sStr As String) As Boolean
      Dim lPos As Long
      Const ALPHA_NUM As String = "abcdefghijklmnopqrstuvwxyz" & _
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
        
      lPos = StrSpn(StrPtr(sStr), StrPtr(ALPHA_NUM))
      IsAlphaNumeric = (lPos = Len(sStr))
      
    End Function
    since it returns a boolean value, you can use it for validation. for example,

    Code:
    If IsAlphaNumeric(myTextBox.text) = true Then
        msgbox "valid"
      End If
    hope this helps

  6. #6
    Hyperactive Member
    Join Date
    Jun 2000
    Posts
    299

    there is a vb function

    IsNumeric which returns a bool.
    ie
    Code:
    Dim MyVar, MyCheck
    MyVar = "53"   ' Assign value.
    MyCheck = IsNumeric(MyVar)   ' Returns True.
    
    MyVar = "459.95"   ' Assign value.
    MyCheck = IsNumeric(MyVar)   ' Returns True.
    
    MyVar = "45 Help"   ' Assign value.
    MyCheck = IsNumeric(MyVar)   ' Returns False.
    not so good if its both... unless you cut it up, bit by bit. That could help.

  7. #7

    Thread Starter
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527

    thanks

    thanks everyone

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