How can I reject letters in a field for number? - 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: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
DR White
Posts: 421
Joined: Fri Aug 23, 2013 12:29 pm
Location: Virginia, USA

How can I reject letters in a field for number? - Solved

Post by DR White » Sat Mar 24, 2018 11:14 am

How can I reject letters in a field that can have numbers, "." and "/", but no letters?

Thanks,

David
Last edited by DR White on Sat Mar 24, 2018 12:34 pm, edited 1 time in total.

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2261
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: How can I reject letters in a field for number?

Post by jmburnod » Sat Mar 24, 2018 11:41 am

Hi David,
This should work

Code: Select all

on keydown pKey
   put "1234567890./" into tMyAllows
   if pKey  is in tMyAllows then
      pass keydown
   end if
end keydown
Best regards
Jean-Marc

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 2792
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria
Contact:

Re: How can I reject letters in a field for number?

Post by richmond62 » Sat Mar 24, 2018 11:47 am

One EXTREMELY CLUNKY, STEAM-DRIVEN SOLUTION coming up:

Code: Select all

on mouseUp
   put empty into fld "f2"
   put fld "f1" into FFF
   put 1 into KOUNT
   repeat until char 1 of FFF is empty
      if (char 1 of FFF = "1") or (char 1 of FFF = "2") or (char 1 of FFF = "3") or (char 1 of FFF = "4") or (char 1 of FFF = "5") or (char 1 of FFF = "6") or (char 1 of FFF = "7") or (char 1 of FFF = "8") or (char 1 of FFF = "9") or (char 1 of FFF = "0") or (char 1 of FFF = ".") or (char 1 of FFF = "/") then
         put char 1 of FFF after fld "f2"
      end if
      delete char 1 of FFF
      add 1 to KOUNT
   end repeat
end mouseUp
{blaming it on my 101 degree temperature :D ]
Rejection.png
Rejection Letters.livecode.zip
Here's the stack.
(1.35 KiB) Downloaded 11 times
And there's Monsieur Burnod "pipping me at the post" :)

DR White
Posts: 421
Joined: Fri Aug 23, 2013 12:29 pm
Location: Virginia, USA

Re: How can I reject letters in a field for number?

Post by DR White » Sat Mar 24, 2018 12:34 pm

Jean-Marc,

WOW. That is so much cleaner then what I was trying to do and it works well.

Thanks So very much,

David
----------------

richmond62,

We program very similar, "STEAM-DRIVEN" style. It gets the job done,
but not in the cleanest and easiest way.

Thanks for your suggestion,

David

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5649
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: How can I reject letters in a field for number? - Solved

Post by dunbarx » Sat Mar 24, 2018 3:52 pm

Before Colin Holgate pipes in, since he is notorious for reducing handlers to the fewest possible lines, Jean-Marc's excellent solution could be:

Code: Select all

on keydown tKey
  if tKey is in "0123456789./" then pass keyDown
end keydown
I only mention this so that the workings of the keyDown message are fully understood, that if the message is not passed, no text is forthComing.

Craig Newman

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”