making a script error illegal characters

I have a script that makes folders, and subfoldres, it askes for the user to type in a name for it. What I need is a way that it will error out and stop running the script and also display a dialog box as to why (illeagle character) such as *,+,< and so on.

I can get it to error but it still makes the foler, there are about 25 of these characters I wish for the user not to use.

on run
tell application "Finder"
et job_number to text returned of (display dialog "Enter the Job Number:" default answer "" buttons {"Cancel", "Ok"} default button 2 with icon 1)
if job_number contains "*" then (display dialog "You entered an illeagl character" buttons {"Ok"} default button 1 with icon 2)
end tell
end run

If I put “if job_number contains “*” then error” it will error but then how do I get my dialog box?

Any help would be appericated.


Try this:


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]