0

我有一个要求,我必须限制用户在他需要输入内容的对话框中输入特殊字符。我只想允许数字和字符。谁能告诉我这是否可能?

代码如下:

display dialog "Enter You Name: " default answer "Name" buttons{"Proceed"}

在默认答案位置,用户不应输入任何特殊字符。我可以通过这样做来限制他吗?

4

1 回答 1

3

你可以尝试这样的事情:

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
于 2013-07-17T13:54:27.240 回答