Avoiding invalid filenames

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
carel
Posts: 58
Joined: Mon Jul 29, 2013 2:49 pm

Avoiding invalid filenames

Post by carel » Thu Sep 05, 2013 4:05 pm

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

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Avoiding invalid filenames

Post by Simon » Thu Sep 05, 2013 8:53 pm

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

carel
Posts: 58
Joined: Mon Jul 29, 2013 2:49 pm

Re: Avoiding invalid filenames

Post by carel » Fri Sep 06, 2013 4:35 pm

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

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Avoiding invalid filenames

Post by Simon » Fri Sep 06, 2013 5:06 pm

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

carel
Posts: 58
Joined: Mon Jul 29, 2013 2:49 pm

Re: Avoiding invalid filenames

Post by carel » Fri Sep 06, 2013 9:16 pm

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

carel
Posts: 58
Joined: Mon Jul 29, 2013 2:49 pm

Re: Avoiding invalid filenames

Post by carel » Fri Sep 06, 2013 9:24 pm

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

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Avoiding invalid filenames

Post by Simon » Fri Sep 06, 2013 9:55 pm

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

carel
Posts: 58
Joined: Mon Jul 29, 2013 2:49 pm

Re: Avoiding invalid filenames

Post by carel » Sat Sep 07, 2013 9:39 am

OK, Thank you!

Post Reply