Jump to content

check char in array?


Go to solution Solved by FireFox,

Recommended Posts

what am I doing wrong here?

Func char_ok($input)
Local $arr = [ 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z', _
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z', _
0,1,2,3,4,5,6,7,8,9 ]
For $x = 1 To UBound($arr)
If $arr[$x - 1] = $input Then Return True
Next
Return False
EndFunc


MsgBox(0,0,char_ok('-'))

The '-' is not in the array so why is it true?

 

TheAutomator. 

Edited by TheAutomator
Link to comment
Share on other sites

  • Solution

Hi,

The problem is when you are comparing a number with your input so your input (which is a string) is converted to a number.

As your input can not be converted to a number, it equals 0. Hence it matches the 0 in your array.

To avoid this add quotes to have strings and not numbers.

Br, FireFox.

Link to comment
Share on other sites

What Firefox said.

Also you'd better use a regular expression for this validation:

Func char_ok($input)
    Return (StringRegExp($input, '(?i)^[[:alnum:]]$') = 1)
EndFunc

MsgBox(0, 0, char_ok('Zr'))

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

  • Moderators

jchd,

 

I know, but i'm not so familiar with regular expressions and I don't find any good tutorials for it..

but thanks for the info ^_^ 

TheAutomator. 

 

You would find one quickly if you cracked open the help file. Not only is there a Regular Expression Tutorial, there are links to other resources. All you have to do is look.

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Good reading!

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

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...