Jump to content

Finding wether a value is alphanumeric...


Recommended Posts

$str1 = "hello"
$str2 = "he11o2"
$str3 = "123"
$str4 = "#123"
$str5 = "&hello"
If _AlphaNum($str1) Then
    MsgBox (0, "test", $str1 & " is Alphanumeric.")
Else
    MsgBox (0, "test", $str1 & " is not alphanumeric.")
EndIf

If _AlphaNum($str2) Then
    MsgBox (0, "test", $str2 & " is Alphanumeric.")
Else
    MsgBox (0, "test", $str2 & " is not alphanumeric.")
EndIf

If _AlphaNum($str3) Then
    MsgBox (0, "test", $str3 & " is Alphanumeric.")
Else
    MsgBox (0, "test", $str3 & " is not alphanumeric.")
EndIf

If _AlphaNum($str4) Then
    MsgBox (0, "test", $str4 & " is Alphanumeric.")
Else
    MsgBox (0, "test", $str4 & " is not alphanumeric.")
EndIf

If _AlphaNum($str5) Then
    MsgBox (0, "test", $str5 & " is Alphanumeric.")
Else
    MsgBox (0, "test", $str5 & " is not alphanumeric.")
EndIf

Func _AlphaNum($s_string)
    If Not StringRegExp($s_string, "[^:alnum]", 0) Then Return 0
    Return 1
EndFunc

Func _URLEncode ($s_url)
    $s_url = String($s_url)
    $s_encoded = ""
    $as_url = StringSplit ($s_url, "")
    For $i=1 To $as_url[0]
        If StringInStr ( "?", $s_encoded ) Then
            If $as_url[$i] <> "&" Then
                If Not _AlphaNum ($as_url[$i]) Then $as_url[$i] = "%" & Asc($as_url[$i])
            EndIf
        EndIf
        If $as_url[$i] = " " Then $as_url[$i] = "%20"
        $s_encoded &= $as_url[$1]
    Next
    Return $s_encoded
EndFunc

The MsgBoxes say that every string is alphanumeric, including "#123" and "&hello"

What is wrong here?

Matt :lmao:

Edited by theguy0000

The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Link to comment
Share on other sites

  • Moderators

Um... what's wrong with StringIsAlNum()?

$a = '#123'
$b = '123'
If StringIsAlNum($a) Then MsgBox(0, $a, 'String is AlphaNum')
If StringIsAlNum($b) Then MsgBox(0, $b, 'String is AlphaNum')

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...