How do I test DATA ENTRY FIELD for just numbers - Solved

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
DR White
Posts: 718
Joined: Fri Aug 23, 2013 12:29 pm

How do I test DATA ENTRY FIELD for just numbers - Solved

Post by DR White » Tue Jul 21, 2015 10:29 am

How do I test a Data entry field for just numbers and decimal point?

Thanks,

David
Last edited by DR White on Mon Jul 27, 2015 2:43 pm, edited 2 times in total.

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: How do I test DATA ENTRY FIELD for just numbers and deci

Post by jmburnod » Tue Jul 21, 2015 10:58 am

Hi David,

You can use this in your field script :

Code: Select all

on keyDown pkey
   if pkey is in "1234567890." then
           put pkey after me
   end if
end keyDown
Best regards
Jean-Marc
https://alternatic.ch

DR White
Posts: 718
Joined: Fri Aug 23, 2013 12:29 pm

Re: How do I test DATA ENTRY FIELD for just numbers and deci

Post by DR White » Tue Jul 21, 2015 12:15 pm

Jean-Marc,

That works Great!! :D

Thanks,

David

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: How do I test DATA ENTRY FIELD for just numbers and deci

Post by MaxV » Tue Jul 21, 2015 3:44 pm

I prefer this:

Code: Select all

on closeField 
  if the text of me is not a number then
     beep
     answer "Please enter a valid number."
     select text of me
  end if
end closeField
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

atout66
Posts: 266
Joined: Wed Feb 02, 2011 12:31 pm

Re: How do I test DATA ENTRY FIELD for just numbers and deci

Post by atout66 » Wed Jul 22, 2015 5:37 pm

You can also use:

Code: Select all

on keyDown k
     if k is a number then pass keyDown
end keyDown
which is closed to Jean-Marc...

Regards, Jean-Paul.
Discovering LiveCode Community 6.5.2.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: How do I test DATA ENTRY FIELD for just numbers and deci

Post by dunbarx » Wed Jul 22, 2015 7:07 pm

Jean-Paul.

The "pass" method has its own charm. But you always need to include the decimal point.

Craig

Post Reply