12 Replies Latest reply on Sep 4, 2013 10:18 AM by CekariYH

    Only accept a numberkey press

    CekariYH

      Title

      Only accept a numberkey press

      Post

           Hi,

            

           I have a field that I want only numbers "0123456789" to be accepted during data imput.

           I tried the OnObjectKeystroke script trigger but don't know how the get the char pressed to test it in an if funktion.

      Furthermore I want the next field to be active when 8 valid numbers has been entered.

            

      Thanks

      Cekari

        • 1. Re: Only accept a numberkey press
          raybaudi
               You could try this script:
                
                    If [ not ValueCount ( FilterValues ( "8¶48¶49¶50¶51¶52¶53¶54¶55¶56¶57¶58¶127" ; Code ( Get ( TriggerKeystroke ) ) ) ) ]
                       Exit Script [ Result: 0 ]
                    End If
                    If [ Length ( Get ( ActiveFieldContents ) ) ≥ 8 and not ValueCount ( FilterValues ( "8¶127" ; Code ( Get ( TriggerKeystroke ) ) ) ) ]
                       Go to Next Field
                       Exit Script [ Result: 0 ]
                    End If

                

          • 2. Re: Only accept a numberkey press
            CekariYH

                 Hi Ray,

                 Thanks, but havn't had time to tst it yet, but will when I return to that part.

                 Looks very advansed in my untrained experince, so I'm not sure what it does. Guess is that the first IF checking for what key was pressed so other than numbers get proccessed properly or vice versa?

                 8=?

                 127=?

                 48-58= "0-9 - ," ?

                  

            • 3. Re: Only accept a numberkey press
              raybaudi

                   8= BackSpace

                   127=Cancel

                   48-57= "0-9" YES ( you could delete the 58 because is wrong )

              • 4. Re: Only accept a numberkey press
                CekariYH

                     Ah, thanks again :-)

                      

                     whats the purpose of the "¶"? new line or...

                     Was Thinking about it and think other "editing" keys should work as well, like arrows etc... will try find a table for keys and chars somewhere.

                • 5. Re: Only accept a numberkey press
                  philmodjunk

                       An auto-enter calculation might be simpler:

                       Filter ( Self ; 9876543210 )

                       with the "do not replace existing value" check box selected will automatically remove all data but the digits 0...9.

                       And if the user needs to input floating point values such as 3.14, you could use:

                       GetAsNumber (Self )

                  • 6. Re: Only accept a numberkey press
                    CekariYH

                         @Phil: Yes, I tried that but then you can't edit the field if you wrote a wrong digit as no keypresses for moving along within the number etc.

                    • 7. Re: Only accept a numberkey press
                      raybaudi

                           ...not to mention the fact that the request also included to automatically go to the next field after 8 characters.

                      • 8. Re: Only accept a numberkey press
                        raybaudi

                        "whats the purpose of the "¶"? new line or..."

                        No, the purpose is creating a list of accepted code

                        • 9. Re: Only accept a numberkey press
                          philmodjunk

                               @Phil: Yes, I tried that but then you can't edit the field if you wrote a wrong digit as no keypresses for moving along within the number etc.

                               You can still be able to edit the field.

                               But Raybaudi makes a good point about the need to advance to the next field at the appropriate time. I thought this approach would make for a very simple script for that purpose, but a quick test reveals that it really doesn't simplify it and since you need the script, you might as well process the keystrokes character by character at the same time.

                          • 10. Re: Only accept a numberkey press
                            CekariYH

                                 @Ray: aha, but then it's a new line char as it works like that in a dialog window but here you get internely a vertical list ;-)

                                  

                                 @Phil: When I tried that I could only use the mousepointer to select 1 or more digits to edit  and not the arrow-keys?

                                 Anyway to go to next field after all is filled in was no problem with some aditional code in same script  :-)

                                 Thanks both of you.

                            • 11. Re: Only accept a numberkey press
                              philmodjunk

                                   @Phil: When I tried that I could only use the mousepointer to select 1 or more digits to edit  and not the arrow-keys?

                                   The arrow and delete keys should all still work with the auto-entered calcualtion. It, by itself, has no influence on what you do with the field. The changes take place after you exit the field. I suspect that your OnLayoutKeystroke script was interfering with your ability to edit the field--and since you need that script anyway, there's no real advantage to the auto-entered calculation. (auto-entered calcs are not script steps, they are set up in Field Options.)

                              • 12. Re: Only accept a numberkey press
                                CekariYH

                                     Hmmm, ok, sure enough, I must have missed to disable the auto-entered setting...