How to limit data entry to only lowercase letters?

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
cooper_tim13
Posts: 4
Joined: Fri May 06, 2016 1:42 pm

How to limit data entry to only lowercase letters?

Post by cooper_tim13 » Sat May 07, 2016 6:30 am

I am making a two-player hangman game, and I have set a limit of 10 characters which is working fine:

Code: Select all

on keyDown
   if the length of me = 10 then
      beep
      else
         pass keyDown
         end if
end keyDown
However, when I try to limit the character input to only lowercase characters, nothing seems to happen. I can still type any character I want.

Code: Select all

on keyDown inkey
   if inkey is in "abcdefghijklmnopqrstuvwxyz" then
      pass keyDown
   else
      beep
   end if
end keyDown
How do I fix this? Thankyou.

paul_gr
Posts: 319
Joined: Fri Dec 08, 2006 7:38 pm
Location: Blenheim, New Zealand

Re: How to limit data entry to only lowercase letters?

Post by paul_gr » Sat May 07, 2016 7:48 am

use something like this in the field script

-------------------------------------------------------
on keyDown theKey
if matchText(theKey,"[A-Z]") is false then
pass keyDown
end if
end keyDown
-------------------------------------------------------

Will block capital letters.

Paul

cooper_tim13
Posts: 4
Joined: Fri May 06, 2016 1:42 pm

Re: How to limit data entry to only lowercase letters?

Post by cooper_tim13 » Sat May 07, 2016 8:27 am

Paul, sorry but this did not do anything. I am still allowed to type in any character.

Also, I want to block all keys, including the spacebar, from being pressed except for a-z, not just uppercase A-Z

Thankyou,
Cooper.

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

Re: How to limit data entry to only lowercase letters?

Post by jmburnod » Sat May 07, 2016 9:18 am

Hi Cooper,
It works with casesensitive = true

Code: Select all

on keyDown inkey
   set the casesensitive to true 
   if inkey is in "abcdefghijklmnopqrstuvwxyz" then
      pass keyDown
   else
      beep
   end if
end keyDown
Best regards
Jean-Marc
https://alternatic.ch

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am
Location: Bordeaux, France

Re: How to limit data entry to only lowercase letters?

Post by Dixie » Sat May 07, 2016 11:00 am

cooper_tim13...

The script posted by 'paul_gr' does work, and is a very nice solution to the problem you wanted solving. I would suggest that you look in the dictionary and read the entry for 'matchText'...

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: How to limit data entry to only lowercase letters?

Post by bn » Sat May 07, 2016 12:22 pm

actually Cooper wanted nothing but lowercase letters a-z, so paul_gr's example would be

Code: Select all

on keyDown theKey
   if matchText(theKey,"[a-z]") is true then
      pass keyDown
   end if
end keyDown
Kind regards
Bernd

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am
Location: Bordeaux, France

Re: How to limit data entry to only lowercase letters?

Post by Dixie » Sat May 07, 2016 12:25 pm

Hi Bernd...

Paul_gr's script does give lowercase and not uppercase !...:-)
His script is correct as it stands

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: How to limit data entry to only lowercase letters?

Post by bn » Sat May 07, 2016 12:27 pm

except that it also accepts number exclamation marks punctuation and so on.

Kind regards
Bernd

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am
Location: Bordeaux, France

Re: How to limit data entry to only lowercase letters?

Post by Dixie » Sat May 07, 2016 12:30 pm

Bernd...:-) You are splitting hairs.
'paul_gr's' script did just what the OP asked for when he replied... the OP did not ask for other things to be taken into consideration until later on in the post.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: How to limit data entry to only lowercase letters?

Post by bn » Sat May 07, 2016 12:40 pm

You are splitting hairs.
:)

reminds me of:

Q: "How are you?"
A: "Fine like a frog hair split by four"
Q: "I did not know frogs had hair?"
A: "See, that's how fine I am"

:) :)

Kind regards
Bernd

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

Re: How to limit data entry to only lowercase letters?

Post by dunbarx » Sat May 07, 2016 6:53 pm

Ho, ho, ho.

Code: Select all

on mouseUp
   set the wholeMatches to "false"
   if "a" = "A" then answer "Same"
   
   set the wholeMatches to "true"
   if "a" = "A" then answer "Same"
end mouseUp
A little knowledge is often a dangerous thing. Right out of the gate, know that if you limit a selection to, say, "a", LC will only look at the "character", not the ASCII value of that character. And the "wholeMtches" don't enter into it. So that methodology is the wrong one.

Craig Newman

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

Re: How to limit data entry to only lowercase letters?

Post by dunbarx » Sat May 07, 2016 6:53 pm

Ho, ho, ho.

Code: Select all

on mouseUp
   set the wholeMatches to "false"
   if "a" = "A" then answer "Same"
   
   set the wholeMatches to "true"
   if "a" = "A" then answer "Same"
end mouseUp
A little knowledge is often a dangerous thing. Right out of the gate, know that if you limit a selection to, say, "a", LC will only look at the "character", not the ASCII value of that character. And the "wholeMtches" don't enter into it. So that methodology is the wrong one.

Craig Newman

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am
Location: Bordeaux, France

Re: How to limit data entry to only lowercase letters?

Post by Dixie » Sat May 07, 2016 7:12 pm

WHAT ?!....

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

Re: How to limit data entry to only lowercase letters?

Post by dunbarx » Sun May 08, 2016 7:40 am

Dixie.

What "what"?

I wanted to make the point that one could compare the ASCII value of "a' with the ASCII value of "A", and get the fact that they are different. But not be able to compare "a" with "A" directly.

"MatchText" is a regex gadget, and though is likely the best solution, may be daunting for a new user.

Craig

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”