Title: Re: Check contents of text field
I need to, on mouseup after clicking a button, check the contents of a small
text field to make sure it doesn't contain any variation of a specific
string of characters.

Example, the field can not contain "My Name" or "my name" or "My name" or
"this is My Name" or "my name rocks" etc.

I'll script the button in the following way ...

on mouseup
if field "f_name" contains [insert script here]
then answer "Your name can't contain the words "My Name" in any form" with
"OK"
if it is "OK" then put empty into field "f_name"
else go to next card
end mouseup

Working with 1.0 Starter Kit.

Also, thank you to those who've helped with the chat code, especially
Michael Fisher and the SimpleChat author.
David

Try the following script in a button with a field called "TheName":

constant cTheWords = "my name", cAdjustedWords = "my_name"

on mouseUp
  put field "TheName" into checkName
  replace return with space in checkName
  replace cTheWords with cAdjustedWords in checkName
  repeat for each word w in checkName
    if w = cAdjustedWords then
      answer warning "Your name can't contain the words '" & cTheWords & "'" \
      with "OK" titled "Oops!"
      put empty into field "TheName"
      exit mouseUp
    end if
  end repeat
  answer information "Off to the next card..." \
  with OK titled "Your Name's OK"
  -- go to next card
end mouseUp

(I've broken long lines with \)

This will replace any carriage returns in the field text with spaces to make sure the following check works OK.  Then it replaces the space between "my" and "name" with underscore to make "my name" appear to be the single word "my_name".  The repeat loop steps through all the words in the adjusted copy of the field looking for the word "my_name".

The above detects "my name" as an error, but happily allows someone with the name "Remmy Namely"!

Obviously you should remove the second answer command and enable the "go to next card" in your actual application.

Cheers

Peter
-- 
Peter Reid
Reid-IT Limited, Loughborough, Leics., UK
Tel: +44 (0)1509 268843 Fax: +44 (0)870 052 7576
E-mail: [EMAIL PROTECTED]
Web: http://www.reidit.co.uk




Reply via email to