Jump to content
Sign in to follow this  
gcue

user input syntax check

Recommended Posts

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!

#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 by gcue

Share this post


Link to post
Share on other sites

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 Gude
How 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

Share this post


Link to post
Share on other sites

yea i thought about that but there are some pretty weird file types out there and i wanted to give the user flexibility.  

Share this post


Link to post
Share on other sites

not sure what that pattern is doing.. 

0=error

1= no error

seems to be the case?

 

Share this post


Link to post
Share on other sites

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 , *.mp4

I should add 'you are welcome' :)

Edited by czardas

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  

×
×
  • Create New...