Page 1 of 1
Restricting field input to ASCII only?
Posted: Thu Oct 18, 2012 2:47 pm
by Simon
I managed to get all the unicode stuff setup to use double byte characters and then the client requested ASCII only
Currently I'm using this hack:
Code: Select all
on closeField
put the htmlText of me into tTxt
if "&#" is in tTxt then
--do something to warn of non ascii characters
There must be a better way?
Thanks
Simon
Re: Restricting field input to ASCII only?
Posted: Fri Oct 19, 2012 9:35 am
by timlit
filtering approaches, 3rd probably being best:
- if character code is > 127(?) then erase last char
- if char is not among the lines "a,b,c...z" then erase last char
- user the perl regex: put replaceText(field id 1, "[^0-9A-Za-zà-ÿ]","") into field id 1 (or similar)
(look up "filter" and 'replacetext" in the dictionary)
Code: Select all
on keyDown pKey
if charToNum(pKey) > 127 then put "this ain't no ASCII"
pass keyDown
end keyDown
Re: Restricting field input to ASCII only?
Posted: Fri Oct 19, 2012 10:55 am
by Klaus
Hi freinds,
unfortunately a 6 year old bug makes the (otherwise clever) "on keydown" script of Tim impossible.
Higher ASCII values (>127) simply do not produce the "keydown" message
Best
Klaus
Re: Restricting field input to ASCII only?
Posted: Fri Oct 19, 2012 11:12 am
by timlit
Klaus,
not sure, what bug you're talking about. My IDE is the old & updated Revolution 4.5 and I have successfully tested methods 1 and 3, with the keydown triggered ok.
3d way, being regex, should work no matter what, right?
Maybe, cheer up and try 122 (letter z)?
Code: Select all
on keyDown pKey
if charToNum(pKey) > 122 then put "this ain't no ASCII"
pass keyDown
end keyDown
Re: Restricting field input to ASCII only?
Posted: Fri Oct 19, 2012 11:35 am
by Klaus
Hi TIm
yes, sorry, my fault!
Code: Select all
on keyDown pKey
if charToNum(pKey) > 127 then
put "this ain't no ASCII"
### !!!!
else
pass keyDown
end if
end keyDown
does indeed work with german umlauts etc.,
but if you press a modifier key like ALT to produce other high ASCII characters,
that is what is what simply bypasses the "keydown" message!
Check this if you are in the developer program:
http://quality.runrev.com/show_bug.cgi?id=3537
Best
Klaus
Re: Restricting field input to ASCII only?
Posted: Fri Oct 19, 2012 11:57 am
by timlit
Of the modifiers, relevant to filtering ASCII, only SHIFT seems to be of importance.
I have just tried it & hence, it's good to go!
Re: Restricting field input to ASCII only?
Posted: Fri Oct 19, 2012 12:03 pm
by Klaus
I don't know the differences german <-> englsih keyboard layout, but try ALT-u or something like that
From the bug report, so you know what I am talking about:
Recipe:
Create a new stack.
Create an editable text field.
Open the message watcher (you'll want to suppress all but unhandled and handled messages.)
Make sure a Latin alphabet is selected from the input menu (the little flag menu.)
I used the standard US keyboard.
Type some characters into the field. Observe that the message watcher shows both
keyDown, rawKeyDown and keyUp, rawKeyUp messages.
Choose a non-Latin input like Greek or Cyrillic (I've also tried it with Chinese
and even upper-ASCII latin characters.) No keyDown or rawKeyDown messages are
shown, but all of the keyUp messages register. For example, when typing using the
U.S. English keyboard, option-u + u also produces no keyDown messages.
Best
Klaus
Re: Restricting field input to ASCII only?
Posted: Fri Oct 19, 2012 3:04 pm
by Simon
Thanks Tim, Klaus,
Yes, my problem has to do with Chinese characters and at least with a QWERTY keyboard the characters use modifier keys so keyDown or rawKeyDown were never triggered. That is why I went with the closeField.
Repeat for each char doesn't work either as it works byte by byte which doesn't catch a double byte char (<127 fails). Need to test repeat for each word.
The "&#" will allow umlauts and other diacritics.
Thanks again,
Simon
Re: Restricting field input to ASCII only?
Posted: Fri Oct 19, 2012 4:01 pm
by Simon
oops, word doesn't word, duh!
Simon