• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Validate user input
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Validate user input (From: Preston Smith <email@hidden>)

  • Prev by Date: Getting finder Labels?
  • Next by Date: Re: Novice question
  • Previous by thread: Re: Validate user input
  • Next by thread: Re: Validate user input
  • Index(es):
    • Date
    • Thread