gcue Posted June 1, 2015 Share Posted June 1, 2015 (edited) hello world!i am trying to validate user input as valid syntax. i am asking the user to fill in an input with file types they would like to process. i would like to check their syntax to make sure they arent missing a comma, period and make sure they have things in the right order. however i am going by with how many asterisks are in the string. my method doesnt seem full proof and i'd like to see if anyone has any better ideas.thanks in advance!expandcollapse popup#include <array.au3> $msg_normal = 0 $string = "*.jpg*.jpeg, *.gif,*wav" $string = StringStripWS($string, 8) StringReplace($string, "*", "") $number_of_asterisks = @extended ;comma check StringReplace($string, ",", "") $number_of_commas = @extended If $number_of_commas <> $number_of_asterisks - 1 Then Debug("please check commas") EndIf ;period check StringReplace($string, ".", "") $number_of_periods = @extended If $number_of_periods <> $number_of_asterisks Then Debug("please check periods") EndIf ;type check $seq_matches = StringRegExp($string, "\*\.", 3) $number_of_types = UBound($seq_matches) If $number_of_types <> $number_of_asterisks Then Debug("please check syntax") EndIf Func Debug($variable1 = "", $variable2 = "", $variable3 = "") ;~ #include <array.au3> ;~ $msg_normal = 0 If IsArray($variable1) Then _ArrayDisplay($variable1) Else If $variable2 <> "" Then $variable1 &= @CRLF & $variable2 EndIf If $variable3 <> "" Then $variable1 &= @CRLF & $variable3 EndIf ClipPut($variable1) MsgBox($msg_normal, "Debug", $variable1) EndIf EndFunc ;==>Debug Edited June 1, 2015 by gcue Link to comment Share on other sites More sharing options...
BrewManNH Posted June 1, 2015 Share Posted June 1, 2015 How about making it easy and using checkboxes instead? If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
gcue Posted June 1, 2015 Author Share Posted June 1, 2015 yea i thought about that but there are some pretty weird file types out there and i wanted to give the user flexibility. Link to comment Share on other sites More sharing options...
czardas Posted June 1, 2015 Share Posted June 1, 2015 (edited) Do you mean something like this?$string = " *.jpg,*.jpeg, *.gif,*.wav " MsgBox(0, "", StringRegExp($string, "(?i)\A(\h*\*\.[0-9a-z]+\h*,)*(\h*\*\.[0-9a-z]+\h*)\z")) Edited June 1, 2015 by czardas small modification to regexp syntax operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
gcue Posted June 1, 2015 Author Share Posted June 1, 2015 not sure what that pattern is doing.. 0=error1= no errorseems to be the case? Link to comment Share on other sites More sharing options...
czardas Posted June 1, 2015 Share Posted June 1, 2015 (edited) 1 signifies that the pattern matches the criteria, so the syntax is okay. Try and break it. Edited June 1, 2015 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
gcue Posted June 1, 2015 Author Share Posted June 1, 2015 simple and beautiful usagethank youuuu!! czardas 1 Link to comment Share on other sites More sharing options...
czardas Posted June 1, 2015 Share Posted June 1, 2015 (edited) There's probably a simpler pattern, but this seems to do what I think you want. The user can add spaces between each file format and extensions can be any length or include numbers e.g. *.pspimage , *.mp4I should add 'you are welcome' Edited June 1, 2015 by czardas FrancescoDiMuro 1 operator64 ArrayWorkshop 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