我可以限制用户在applescript的对话框中不输入特殊字符吗?
问题描述:
我有一个要求,我必须限制用户在他需要输入内容的对话框中输入特殊字符。我只想让数字和字符。谁能告诉我是否有可能?我可以限制用户在applescript的对话框中不输入特殊字符吗?
的代码是这样的:我可以限制他这样做
display dialog "Enter You Name: " default answer "Name" buttons{"Proceed"}
在默认答案的地方,用户不应该进入任何特殊字符..?
答
你可以尝试这样的事情:
set allowedLetters to characters of (do shell script "printf \"%c\" {a..z}")
set allowedNumbers to characters of (do shell script "printf \"%c\" {0..9}")
set allowedAll to allowedLetters & allowedNumbers & space
repeat
set response to text returned of (display dialog "Enter You Name: " default answer "Name" buttons {"Proceed"} default button 1)
try
repeat with aCharacter in response
if (aCharacter as text) is not in allowedAll then
display dialog "Please enter letters and numbers only" buttons {"OK"} cancel button 1 default button 1
end if
end repeat
exit repeat
end try
end repeat
return response
感谢队友:)它为我工作:) –