Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[view] field, pattern match input filtering!

 [1/1] from: moliad::aei::ca at: 27-Aug-2006 23:50


hi all, next of these little installments on improving capabilities of view field, input control: This hook example, will filter out the input according to a parse rule you define. This allows you much more control over simple key code filtering. The following input filter is very usefull, its a full blown example on how to filter out north-american phone numbers: it allows 3 forms to be entered only, any deviation, is simply ignored when typing text! For other patterns, just change the 'INPUT-RULE below to match according to any valid parse rule. The only detail of note, is that you must allow the parse rule to cover from zero to all characters up to the last, which is why I supply more than one rule here and set them as being optional in cascade ( 0 1 before blocks mean zero or one times the next rule ) , so that the end of the rule is optional, until the characters up to that point are filled in. possible patterns in the following example (# being any 0-9 digit): (###)###-#### ###-###-#### ###-#### again, have fun... next installment will be a great gift to the community.... an interactive parse tester! ;---------------------------- code snippet ---------------------- digit: charset [#"0" - #"9"] threes: [ 1 3 digit ] fours: [1 4 digit ] input-rule: [[ "(" 0 1 [ threes 0 1 [")" 0 1 [threes 0 1 ["-" 0 1 fours ]]]]] | [ threes "-" threes "-" 0 1 fours] | [threes "-" 0 1 fours] | [ threes] ] key-hook: func [ face event /local ignore new-string ][ probe event/key new-string: join face/text event/key if any [ ignore: parse new-string [input-rule] ignore: found? find [#"^M" #"^-" up down left right home end #"^~" #"^H"] event/key event/key = #"^[" ][ unless ignore [ unfocus face ] ] not ignore ]