Avoiding invalid filenames
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Avoiding invalid filenames
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
Or if I can just determine if just alphanumerics was entered ??
Thanks,
Carel
Re: Avoiding invalid filenames
Hi Carel,
Here is a manual way:
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
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
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!
Re: Avoiding invalid filenames
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
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
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
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!
Re: Avoiding invalid filenames
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
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
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
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
pass keyDown allows the key to go into the field.
Without that the message just stops there.
If you just had:
No keys would ever leave that message.
Simon
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!