Notwithstanding that there may be other considerations or approaches (eg on closeField), depending on your user interface and program flow, where you have multiple possible triggers of the same code, you can easily avoid code duplication by leveraging the message path.
Create a handler in a suitable place in the message path (group script, card script or stack script, for example)
Code: Select all
on validateInput pData
if pData is not an integer then
answer "Invalid input. You entered" && quote & pData & quote && "which is not an integer."
end if
--and or your code that you want to avoid duplicating
end validateInput
Then in the different trigger places, you can
Code: Select all
on enterInField
put the text of me into tData
validateInput tData
end enterInField
etc etc for returnInField, closeField