Page 1 of 1

Avoiding invalid filenames

Posted: Thu Sep 05, 2013 4:05 pm
by carel
I'm asking user input to create a file - how do I detect invalid characters (!@#$%^&*) entered? - I do not even know what all the invalid characters are.

Or if I can just determine if just alphanumerics was entered ??

Thanks,

Carel

Re: Avoiding invalid filenames

Posted: Thu Sep 05, 2013 8:53 pm
by Simon
Hi Carel,
Here is a manual way:

Code: Select all

on keyDown tKey
   put "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,1,2,3,4,5,6,7,8,9,0,-,_,." into tLetters
   if tKey is not in tLetters then
      answer "use only..."
   else
      pass keyDown
   end if
end keyDown
Put that in your field.
There is "isNumber" which I probably could have used up there.
Of course this does not work with "ask file".

Simon

Re: Avoiding invalid filenames

Posted: Fri Sep 06, 2013 4:35 pm
by carel
Thanks for the info Simon but it is not working for me.

I have the following:

I have a button "save", and text field "LessonName" in which the user types the filename.

I do not understand the "is not in" it just don't make sense to me, maybe you can explain the use of it?

on mouseUp
put "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,1,2,3,4,5,6,7,8,9,0,-, ,." into tLetters
if field "LessonName" is not in tLetters then
answer "Invalid Lesson Name"
exit mouseUp
else
pass mouseUp
end if
local tFullUrl
global workingfolder
put WorkingFolder & "/" && field "LessonName" & ".sws" into tFullUrl
open file tFullUrl for write
write WordsToAdd to file tFullUrl
close file tFullUrl
go to card 4
end mouseUp

Thanks,

Carel

Re: Avoiding invalid filenames

Posted: Fri Sep 06, 2013 5:06 pm
by Simon
Hi Carel,
You skipped the "on keyDown"?
You should put the script I posted into the script of the field "LessonName"
It will test each key pressed to see if it matches a number or letter in tName.
So it ends up as:
is "h" in this list "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,1,2,3,4,5,6,7,8,9,0,-, ,." (no case sesitivity)

Simon

Re: Avoiding invalid filenames

Posted: Fri Sep 06, 2013 9:16 pm
by carel
Thanks Simon, I get it now.

I think I'll just set a Boolean variable instead of the message and then just evaluate the Boolean when the user click on the Save button and tell him it is invalid.

Thanks,

Carel

Re: Avoiding invalid filenames

Posted: Fri Sep 06, 2013 9:24 pm
by carel
Just one more thing - What does pass keyDown do?

pass the key to the field?

Would I then have to do:

if tKey is not in tLetters then
put false into AllValidCharactersEntered
pass keyDown
end if

Re: Avoiding invalid filenames

Posted: Fri Sep 06, 2013 9:55 pm
by Simon
pass keyDown allows the key to go into the field.
Without that the message just stops there.

If you just had:

Code: Select all

on keyDown tKey
--do what is in here, and when done tell the messagepath that keyDown was handled
end keyDown

No keys would ever leave that message.

Simon

Re: Avoiding invalid filenames

Posted: Sat Sep 07, 2013 9:39 am
by carel
OK, Thank you!