Sign in to follow this  
Followers 0
theguy0000

Finding wether a value is alphanumeric...

5 posts in this topic

#1 ·  Posted (edited)

$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

Share this post


Link to post
Share on other sites



Func _AlphaNum($s_string)

If StringRegExp($s_string, "[^:alnum:]", 0) Then Return 0

Return 1

EndFunc

Got rid of Not, and put : at the end of alnum.

Share this post


Link to post
Share on other sites

aha. thanks.

Matt :lmao:


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

Share this post


Link to post
Share on other sites

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')


[center]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.[/center]

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

oh I didnt even notice that :">

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

Share this post


Link to post
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
Sign in to follow this  
Followers 0