我有一个要求,即我必须限制用户在对话框中输入他需要输入的特殊字符。我只允许使用数字和字符。有人能告诉我这是否可能吗??
代码如下:
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