Limiting text input in a text entry field

Philippe Pezard philpez at mac.com
Sun Aug 17 13:58:01 EDT 2008


I use a little scrip to verify the quality of numerical entrees, able to work with clasical keyboard or books without number keypad.
It's as following, perharps it may be useful for your purpose :

if Pref = 1 then                                       -- for use with laptop and numeric key pad
  if theKey is not in "1234567890,." then   -- , because it's for french use where "," can be use instead of "."
    beep
  else 
    pass keyDown
  end if
end if
  
if Pref = 2 then                                       -- for use with notebook without pressing on uppercase key
  if theKey is not in "&é'(§è!çà,;" and theKey is not quote then 
      beep
    else
      -- conversion
      put "124567890,.3" into Varsortie
      put "&é'(§è!çà,;" & quote into Varentree
      repeat with i = 1 to 12
        if theKey is (char i of Varentree) then 
          put (char i of Varsortie) after the target
          exit repeat
        end if
      end repeat
  end if
end if
end keyDown

It seem to work well ...

Best regards
P. Pézard
----------------------------------------
To: How to use Revolution <use-revolution at lists.runrev.com>
Message-ID: <ACAD052D-7553-4BA7-85A4-49B76A25506D at major-k.de>
Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes

Hi Neil,

Hi!

This should be a straightforward thing but I can only partially get  
it working.
I'm trying to limit a text fields input to only numbers and integers -
I can get numbers only by using:

on keyDown theKey
 if theKey is not a number then beep
 else pass keyDown
end keyDown

but I can't get it to accept integers, even if I specify 'an  
integer' in above.

I think I'm missing something simple!

I think you need something like:

on keyDown theKey
  if theKey is not in ".0123456789"
     then beep
   else
      pass keyDown
   end if
end keyDown

Cheers
Neil

Best

Klaus Major
klaus at major-k.de
http://www.major-k.de



More information about the use-livecode mailing list