Page 1 of 1

Numbers or text only in a field?

Posted: Mon Oct 12, 2009 12:28 am
by TodayIsTheDay
Is there a simple way to only let a user enter numbers into a text box? (or letters only for that matter?)

In another language I remember where you could mask or set a field to only accept one or the other. Is there something like that in RunRev?

Posted: Mon Oct 12, 2009 11:12 am
by Mark Smith
If you put this in the script of your field:

Code: Select all

on keyDown pKey
   if pKey is in "0123456789." then pass keydown
end keyDown
The user will be restricted to entering only the characters listed.

Of course it gets more complex if you want to avoid a leading decimal point, or multiple decimal points, but you get the idea.

Best,

Mark Smith

Posted: Mon Oct 12, 2009 5:03 pm
by SparkOut
You can get more comprehensive with this too. There are various stacks around which you can examine, a handy one that I don't have to look up where to find is in RevOnline (v 3.5+) by George Brackett, search for "Allowed Chars Behavior".

Posted: Mon Oct 12, 2009 8:11 pm
by chris9610
Ok boys I am new but here is a script which has evolved into one of my fields.

Code: Select all

on keyDown theKey
   if the length of the selectedText of me > 0 and thekey is a number then pass keyDown 
   else if thekey is "." and offset(".",me) = 0 then pass keydown
   else if theKey is not a number or the length of me >= 5 then focus me
   else pass keyDown
end keyDown
on exitfield
   put format("%05.2f",me) into newvar
   put newvar into me
end exitfield
on closefield
   put format("%05.2f",me) into newvar
   put newvar into me
end closefield
This may not be perfect but it works.

Posted: Mon Oct 12, 2009 10:36 pm
by TodayIsTheDay
Thanks! That gives me a couple of routes to try!