Page 1 of 2

check field for letters

Posted: Tue Oct 28, 2014 9:29 pm
by DavJans
I have found lots of help on what I need but all seem to want me to use pKey. if pKey is not a number then ...
I think this will not work for me because I have buttons that auto fill fields with text. Maybe I'm wrong.

What I would like is to check the field AFTER data entry for letters.

if fld "field 1" contains "a-z" then
answer "no letters allowed"

is this doable?

Thank you in advance and you are all awesome :)

Re: check field for letters

Posted: Tue Oct 28, 2014 10:49 pm
by dunbarx
Hi.

Why not loop through all the chars in the field and eliminate those that are in "abcd...z"? Case would not matter, which is a benefit. And "repeat for each..." is really, really fast. Write back if you get stuck, but this should be fun.

Craig Newman

Edit, upon rereading, I see what you really asked for. Now you would loop through all 26 chars, and stop if even one of them was in the source text. Faster yet, the size of the source now being irrelevant. The first post would be a way to delete the offending chars.

I assume there is a short regex solution as well.

Re: check field for letters

Posted: Wed Oct 29, 2014 11:25 am
by [-hh]
The following uses a regular expression.

Code: Select all

on mouseUp
  if matchtext(fld 1 ,"[a-zA-Z]")
  then answer "No letters (a-z or A-Z) allowed."
end mouseUp
Warning: This doesn't find international chars (like "ΓΌ").

Re: check field for letters

Posted: Wed Oct 29, 2014 4:31 pm
by DavJans
Great step in the right direction I think, but of course there is another problem. Here is how I used your code.

on closeField
if matchtext(fld "welder" ,"[a-zA-Z]") then
answer "No letters (a-z or A-Z) allowed."
focus on fld "welder"
BREAK
end if
end closeField

However its not working right, It wont refocus on the field as I expected and It is running the openField script on the next field selected.

Re: check field for letters

Posted: Wed Oct 29, 2014 5:47 pm
by [-hh]
You could try:

Code: Select all

-- in card's script (for all fields on card)
-- or in field's script (for that field only)
on closeField
  if matchtext(text of the target,"[a-zA-Z]") then 
    answer "No letters (a-z or A-Z) allowed."
    select text of the target
  else pass closeField
end closeField

Re: check field for letters

Posted: Wed Oct 29, 2014 5:56 pm
by MaxV
The best solution is: 8)
########CODE#######
on keyDown pKey
if pKey is not a number and pKey is not "." then
beep
else
pass keyDown
end if
end keyDown
#####END OF CODE#####

Re: check field for letters

Posted: Wed Oct 29, 2014 6:06 pm
by [-hh]
Depends upon what he wants.
For example space, minus, plus, parentheses, brackets are also allowed with phone numbers.
Or: Numbers and "." are *not* the complement of a-z & A-Z :-)

Re: check field for letters

Posted: Wed Oct 29, 2014 6:23 pm
by MaxV
[-hh] wrote:Depends upon what he wants.
For example space, minus, plus, parentheses, brackets are also allowed with phone numbers.
Or: Numbers and "." are *not* the complement of a-z & A-Z :-)
If you need more, just add it: :lol:
########CODE#######
on keyDown pKey
if pKey is not a number and pKey is not in "+-.,()[]{}" then
beep
else
pass keyDown
end if
end keyDown
#####END OF CODE#####
However you solution is better with autofill button.

Re: check field for letters

Posted: Wed Oct 29, 2014 6:28 pm
by dunbarx
The OP wanted to validate AFTER the field had been populated. That is, all at once at some later time. Any solution that uses "keydown" is validating on the fly.

Craig

Re: check field for letters

Posted: Wed Oct 29, 2014 6:46 pm
by [-hh]
@MaxV.
It's often advantageous to consider what is simpler to enumerate, a set or its complement.
May be you are right. But just to keep you busy with beeping:
Now assume he wants to have some words containing *only* a-z or A-Z to be typed (for example for a userName).

Re: check field for letters

Posted: Wed Oct 29, 2014 7:05 pm
by DavJans
-- in card's script (for all fields on card)
-- or in field's script (for that field only)
on closeField
if matchtext(text of the target,"[a-zA-Z]") then
answer "No letters (a-z or A-Z) allowed."
select text of the target
else pass closeField
end closeField
That did it, almost, Had to Add a break after select text of.. and i had to change the target to fld "welder" then it worked perfect, thank you all for your help.

Re: check field for letters

Posted: Wed Oct 29, 2014 7:23 pm
by [-hh]
Now all joking aside.

What's the shortest way to have a check that a string contains only unicode 'letters' (incl. internatonal diacritics and 'twobyte' chars)?

Is "Mr. Regex" back from holidays?

Re: check field for letters

Posted: Wed Oct 29, 2014 10:44 pm
by Simon
I did see Mr. Regex in here earlier today.

Simon

Re: check field for letters

Posted: Thu Oct 30, 2014 5:06 pm
by jacque
The "break" command is only for use in switch statements. If it works here, it's by accident and I wouldn't rely on it. You shouldn't need it anyway, the "if" clause should handle everything by itself.

Re: check field for letters

Posted: Thu Oct 30, 2014 5:55 pm
by DavJans
I found that If using the mouse to click into another field, it will give the message about no letters, but it will still move to the clicked on field leaving the field with illegal characters :(