Sign in to follow this  
Followers 0
randd

Input Validation

8 posts in this topic

I've searched through the forums and I couldn't find anything for "input validation" or "input validate".

I need to validate some user supplied input and I'm not really sure how to go about doing it. It's a pretty basic input box that I'm calling to get the user to supply a date (mm/dd/yyyy). I want to verify that the user has supplied the correct format before proceeding. I know I can loop the input msgbox until the proper input is recieved, but how do I check the input and make sure it's properly formated?

I the end I'll just loop the msgbox until valid input is supplied in the proper format.

I figure that once I understand this I'll be able to use the concept on all user supplied input. I don't want to accept any data from a user unless I've validated it. I just don't know how to write up the validation piece.

Thanks for the help!


Raoul S. Duke: Few people understand the psychology of dealing with a highway traffic cop. Your normal speeder will panic and immediately pull over to the side. This is wrong. It arouses contempt in the cop-heart. Make the bastard chase you. He will follow.

Share this post


Link to post
Share on other sites



Thanks Larry. I appreciate the quick response. I'll post my results here later.


Raoul S. Duke: Few people understand the psychology of dealing with a highway traffic cop. Your normal speeder will panic and immediately pull over to the side. This is wrong. It arouses contempt in the cop-heart. Make the bastard chase you. He will follow.

Share this post


Link to post
Share on other sites

My problem is I don't know how to print $statdate now that it's actually an array. I tried $startdate[1-3] but that doesn't work. I know that $startdate[0] contains the number of elements in the array. I'm not sure how to get the array back into a "normal" string again. Should I use a variable and print the array inside a for next loop?

for blah blah print $startdate[$v] next? Or is it proper to assign the string to a new variable before I perform the split?

Here's my code now.

$bGood=0
While Not $bGood

;send popup asking for date mm/dd/yyyy
    $startdate = InputBox("Question", "Start Date?  (format: mm/dd/yyyy)", "", "")
  
    If $startdate = "" then; if startdate blank go through and use today's date
  $startdateanswer = MsgBox(4, "Question", "No Value Entered.  Use today's date?")
  If $startdateanswer = 7 Then
     MsgBox(4096, "Error", "Execution halted.")
     EXIT
  Else
  $startdate = @MON & "/" & @MDAY & "/" & @YEAR; set start date to today
  EndIf
    EndIf
    
    $startdate = StringSplit($startdate,"/")
    If $startdate[0] = 3 and StringLen($startdate[1])=2 And StringLen($startdate[2])=2 And _
           StringLen($startdate[3]) = 4 And StringIsDigit($startdate[1]) And StringIsDigit($startdate[2]) And _
           StringIsDigit($startdate[3]) Then $bGood = 1
Wend

PS. What should I be using on my code to webify it so that my tabs are correctly displayed?


Raoul S. Duke: Few people understand the psychology of dealing with a highway traffic cop. Your normal speeder will panic and immediately pull over to the side. This is wrong. It arouses contempt in the cop-heart. Make the bastard chase you. He will follow.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

$WholeDate = $startdate[1] & "/" & $startdate[2] & "/" & $startdate[3]

PS. What should I be using on my code to webify it so that my tabs are correctly displayed?

You could run Tidy which will clean up the code for you and can convert all tabs to spaces... Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

It is better in this situation to use DO-Until instead of While-Wend

$bGood=0
Do
  ;send popup asking for date mm/dd/yyyy
    $startdate = InputBox("Question", "Start Date?  (format: mm/dd/yyyy)", "", "")

    If $startdate = "" then; if startdate blank go through and use today's date
         $startdateanswer = MsgBox(4, "Question", "No Value Entered.  Use today's date?")
         If $startdateanswer = 7 Then
              MsgBox(4096, "Error", "Execution halted.")
              EXIT
         Else
              $startdate = @MON & "/" & @MDAY & "/" & @YEAR; set start date to today
              $bGood = 1
        EndIf
    Else
         $TESTdate = StringSplit($startdate,"/")
         If $TESTdate[0] = 3 and StringLen($TESTdate[1])=2 And _
                 StringLen($TESTdate[2])=2 And StringLen($TESTdate[3]) = 4 And _
                 StringIsDigit($TESTdate[1]) And StringIsDigit($TESTdate[2]) And _
                 StringIsDigit($TESTdate[3]) Then $bGood = 1
    EndIf
Until $bGood

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Share this post


Link to post
Share on other sites

Thanks. I'm going to see if I can whip up some more code to verify date validity.

01-12, 01-31,1980+

I'm working on some other portion of the code now. Damn java windows create the window first and then populate with data so the winwait function doesn't have the desired result.

No result is white window, results is purple. I'm going to have to see if I can match some pixels then continue with the script instead of doing the winwaitactive command.

Thanks for all the help!


Raoul S. Duke: Few people understand the psychology of dealing with a highway traffic cop. Your normal speeder will panic and immediately pull over to the side. This is wrong. It arouses contempt in the cop-heart. Make the bastard chase you. He will follow.

Share this post


Link to post
Share on other sites

I would just like to thank whomever was responsible for writing the pixel matching code. It has proved an life saver with java windows and it only took a few tries before I got the hang of how it works!

So 'Thank you!'.


Raoul S. Duke: Few people understand the psychology of dealing with a highway traffic cop. Your normal speeder will panic and immediately pull over to the side. This is wrong. It arouses contempt in the cop-heart. Make the bastard chase you. He will follow.

Share this post


Link to post
Share on other sites

My problem is I don't know how to print $statdate now that it's actually an array.  I tried $startdate[1-3] but that doesn't work.  I know that $startdate[0] contains the number of elements in the array.  I'm not sure how to get the array back into a "normal" string again.  Should I use a variable and print the array inside a for next loop?

for blah blah print $startdate[$v] next?  Or is it proper to assign the string to a new variable before I perform the split?

Here's my code now.

$bGood=0
While Not $bGood

;send popup asking for date mm/dd/yyyy
    $startdate = InputBox("Question", "Start Date?  (format: mm/dd/yyyy)", "", "")
  
    If $startdate = "" then; if startdate blank go through and use today's date
  $startdateanswer = MsgBox(4, "Question", "No Value Entered.  Use today's date?")
  If $startdateanswer = 7 Then
    MsgBox(4096, "Error", "Execution halted.")
    EXIT
  Else
  $startdate = @MON & "/" & @MDAY & "/" & @YEAR; set start date to today
  EndIf
    EndIf
    
    $startdate = StringSplit($startdate,"/")
    If $startdate[0] = 3 and StringLen($startdate[1])=2 And StringLen($startdate[2])=2 And _
           StringLen($startdate[3]) = 4 And StringIsDigit($startdate[1]) And StringIsDigit($startdate[2]) And _
           StringIsDigit($startdate[3]) Then $bGood = 1
Wend

PS.  What should I be using on my code to webify it so that my tabs are correctly displayed?

I'll tell you how I've gotton around that is with different input boxes for the month day and year that way it doesn't even matter if you're a brit or a yank like me

Rick


Only $2.00 with Resale Rights How to Block Better for Martial Artists and NonMartial Artistshttp://kirkhamsebooks.com/MartialArts/Bloc...tterEbook_m.htm

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