ShadowElf Posted February 3, 2010 Share Posted February 3, 2010 I need to check if a strind is format like: -letters -letters093 no spaces or other characters. I need to check before create a mysql table pls help I like IT: php, mysql, codeingiter, css, jquery and AUTOIT Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 3, 2010 Moderators Share Posted February 3, 2010 ShadowElf,What have you tried so far? What is the precise format you want? Is it a series of any number of letters, followed by either nothing or the digits "093"?M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
ShadowElf Posted February 3, 2010 Author Share Posted February 3, 2010 format ONLY LETTERS or FIRST letter and after numbers examples asdzc -> OK asdjasd02389 -> ok 231321asd -> NOT OK 90423j)(* -> NOT OK asd90asd90 -> OK asd*& -> NOT ok max 20 chars I like IT: php, mysql, codeingiter, css, jquery and AUTOIT Link to comment Share on other sites More sharing options...
ShadowElf Posted February 3, 2010 Author Share Posted February 3, 2010 thx I like IT: php, mysql, codeingiter, css, jquery and AUTOIT Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 3, 2010 Moderators Share Posted February 3, 2010 Thanubis,Nice.I have to keep reminding myself that just because you can do something with a RegEx, it does not always make sense to actually do so.If you are not a guru in the blasted things, it is ofter easier (and faster!) to use other functions. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
jchd Posted February 3, 2010 Share Posted February 3, 2010 format ONLY LETTERS or FIRST letter and after numbers examples asdzc -> OK asdjasd02389 -> ok 231321asd -> NOT OK 90423j)(* -> NOT OK asd90asd90 -> OK asd*& -> NOT ok max 20 chars From "ONLY LETTERS or FIRST letter and after numbers" one may translate it into: "one or more [english] letter (casing?) followed by zero or more [decimal] digits" in the limit of 20 characters. The 20c limit is easy: If StringLength($str) > 20 Then ... $str is rejected , or truncated The condition above would translate in turn into the regexp: [a-z]+\d* If casing should be ignored, make it (?i)[a-z]+\d* or [a-zA-Z]+\d* Only catch: this doesn't cope with one of your examples: asd90asd90 -> OK So either your actual rules are in fact more complex than you said, or this example is invalid. Only you can read your mind 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 hereRegExp tutorial: enough to get startedPCRE 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 More sharing options...
martin Posted February 3, 2010 Share Posted February 3, 2010 (edited) $s = "oidfgdgu73456548" $r = StringRegExp($s, "\D+\d*", 1) If IsArray($r) and $r[0] = $s Then ConsoleWrite($s & "< Allowed" & @CRLF) Else ConsoleWrite($s & "< Not Allowed" & @CRLF) EndIf EDIT: Added check for return being an array Edited February 3, 2010 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
jchd Posted February 3, 2010 Share Posted February 3, 2010 $r = StringRegExp($s, "\D+\d*", 1) Hi Martin, Sorry but this doesn't work as \D allows non-letters & non-digits ahead: $str = "$got you!159" would incorrectly match. [:alpha:] or [a-z] wouldn't tolerate that. 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 hereRegExp tutorial: enough to get startedPCRE 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 More sharing options...
Bowmore Posted February 3, 2010 Share Posted February 3, 2010 (edited) One of the many ways you could do this using StringRegExp() if you wanted Global $aTest[6] $aTest[0] = "asdzc"; -> OK $aTest[1] = "asdjasd02389"; -> ok $aTest[2] = "231321asd"; -> NOT OK $aTest[3] = "90423j)(*"; -> NOT OK $aTest[4] = "asd90asd90"; -> OK $aTest[5] = "asd*&"; -> NOT ok For $i = 0 To 5 If StringRegExp($aTest[$i],"^[[:alpha:]][[:alnum:]]{0,19}{:content:}quot;) Then MsgBox(0,"Test Result" , $aTest[$i] & " is valid") Else MsgBox(0,"Test Result" , $aTest[$i] & " is not valid") EndIf Next Explanation of the regex pattern "^[[:alpha:]][[:alnum:]]{0,19}{:content:}quot; «^» Assert position at the beginning of a line (at beginning of the string or after a line break character) «[[:alpha:]]» Match a single character in the range A to Z or a to z «[[:alnum:]]{0,19}» Match a single character present in the range A to Z or a to z or 0 to 9 as many times as posible, between zero and 19 times «$» Assert position at the end of a line (at the end of the string or before a line break character) i.e. make sure all characters are include in the match Edited February 3, 2010 by Bowmore "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook Link to comment Share on other sites More sharing options...
Malkey Posted February 3, 2010 Share Posted February 3, 2010 And another attempt. Local $sMessage, $sResults Local $aTestString[8][2] = [["asdzcasddzc", "OK"],["asdjasd02389", "OK"],["asd90asd90", "OK"], _ ["231321asd", "NOT OK"],["90423jr)(*", "NOT OK"],["asdasdasd*&", "NOT OK"], _ ["asd90asd90asd", "NOT OK"],["asdzcasddzc12345678910", "NOT OK"]] For $i = 0 To UBound($aTestString) - 1 $sMessage = "NOT OK" If (StringRegExp($aTestString[$i][0], "^[a-z]") And StringRegExp($aTestString[$i][0], "\d$")) And _ ; If start with letter & end with digit - ok StringLen($aTestString[$i][0]) <= 20 Or _ ; If less than or equal to 20 characters - ok (StringRegExp($aTestString[$i][0], "[^a-z]") = 0) Then $sMessage = "OK" ; If only letters - ok $sResults &= $aTestString[$i][0] & @TAB & $aTestString[$i][1] & " expected. Result is " & $sMessage & @CRLF Next MsgBox(0, "Results", $sResults) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now