Macos 我可以限制用户不在applescript的对话框中输入特殊字符吗?

Macos 我可以限制用户不在applescript的对话框中输入特殊字符吗?,macos,applescript,osx-lion,osx-mountain-lion,Macos,Applescript,Osx Lion,Osx Mountain Lion,我有一个要求,我必须限制用户在对话框中输入特殊字符,他必须在对话框中输入某些内容。我只允许数字和字符。谁能告诉我这是否可能 代码如下所示: 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 chara

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

代码如下所示:

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

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

你可以试试这样的方法:

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

您可以尝试以下方法:

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