Re: Validate user input
Re: Validate user input
- Subject: Re: Validate user input
- From: What does not kill you only makes you stronger <email@hidden>
- Date: Tue, 06 Nov 2001 18:59:12 -0600
on 11/06/01 10:43 AM, email@hidden wrote:
>
How do I confirm that a user has entered only numerals, or certain
>
punctuation marks, into a dialog box?
Not the prettiest code, but I wasn't shooting for pretty.
Nate
(Uses a bit of borrowed code from Michelle Steiner's response.)
on run
set kValidAnswer to getData("Enter a numeric number")
activate
display dialog kValidAnswer
end run
on getData(kDialogtext)
set kDataInput to text returned of (display dialog kDialogtext default
answer "")
testData(kDataInput)
end getData
on testData(kDataInput)
set kValidationList to "1234567890" --other validation characters here
if kDataInput = "" then
getData("Not a valid response. Try again!")
else
repeat with testchar in kDataInput
set kValidation to false
if (offset of (testchar) in kValidationList) is 0 then
exit repeat
else
set kValidation to true
end if
end repeat
if kValidation = true then
return kDataInput
else
getData("Try again. Please enter a numeric number:")
end if
end if
end testData