8 Replies Latest reply on May 11, 2011 5:37 PM by LaRetta_1

    Specify text field format to AAA####

    Parag

      Title

      Specify text field format to AAA####

      Post

      How do I specify the text field format to entry of AAA#### only? e.g. data in the format of ABC1234 only will be accepted.

        • 1. Re: Specify text field format to AAA####
          LaRetta_1

          Are you saying that you want the first three characters to always be ANY text (AAA or ABC etc) and they must be capitalized and always three and that then the next four characters can only be number and there must be four numbers (or at least 0001) and total length must be exactly 7 characters total?

          • 2. Re: Specify text field format to AAA####
            Parag

            Yep, that's exactly right! :)

            • 3. Re: Specify text field format to AAA####
              raybaudi

              May be so:

              IsEmpty ( Self )
              or (
              Length ( Self ) = 7 and
              Length ( Filter ( Left ( Self ; 3 ) ; "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ) )  = 3 and
              Length ( Filter ( Right ( Self ; 4 ) ; 1234567890 ) )  = 4 and
              GetAsNumber ( Self ) > 0
              )

              • 4. Re: Specify text field format to AAA####
                LaRetta_1

                To handle the caps, use auto-enter calculation (replace) with Upper ( Self ).

                For validation, use calculation of EDITED:

                Length ( Filter (  Upper ( Left ( Self ; 3 ) ) ; "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ) ) = 3
                and
                Length ( Filter ( Right ( Self ; 4 ) ; "0123456789" )  ) = 4
                and
                Length ( Self ) = 7

                Provide a message to the user if validation fails showing them how it should be formatted.

                • 5. Re: Specify text field format to AAA####
                  philmodjunk

                  This captures the error after the record is committed unless you use it in a script that is triggered OnObjectSave or OnObjectExit. I'd do one or both and then also consider whether a keystroke triggered script that rejects keystrokes that are "out of pattern" might also help here by acting as a kind of "input mask" to prevent miskeys at the moment they occur.

                  • 6. Re: Specify text field format to AAA####
                    Parag

                    Excellent, thank so much... can you advise what kind of script I can trigger?

                    There are no script functions that reference validation or caculation. The only thing I can find is "Insert Calculated Result".

                    • 7. Re: Specify text field format to AAA####
                      philmodjunk

                      You would use OnObjectKeystroke to run a script that evaluates each key as it is pressed and rejects any that don't fit the pattern.

                      Set Variable [$key ; Get ( TriggerKeyStroke ) ]
                      If [ $Key = char ( 9 ) or $key = char ( 10 ) or $key = Char ( 127 ) or $key = Char ( 8 ) //tab, enter, delete or Backspace was pressed ]
                         Exit Script [] //accept these keys so field can be edited and/or exited
                      Else IF [ length ( YourTable::YourField ) > 7 // full pattern has been entered ]
                         Exit Script [false] // exit script [false] rejects the keystroke
                      Else IF [ Length ( YourTable::YourField ) < 2 and Length ( Filter ( $key ; "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ) ) ]
                         Exit Script [] // accept key if it is one of 1st three chars and is Upper case A ... Z
                      Else IF [ Length ( Filter ( $key ; 9876543210 ) ) ]
                         Exit Script []  // accept key if it is one of last 4 chars and 0 ... 9
                      Else
                         Exit Script [false] // reject every other key stroke.
                      End IF

                      Note, You may only want to use Char ( 9 ) in the first IF step, if you use the default behavior setting where tab should exit the field. If you select Enter as a key stroke use Char ( 10 ) and Char ( 13 ) can be used to identify the Return key. All of the keys you choose to test for in this first If step, should also be selected in the Inspector's behavior section on the Data tab.

                      • 8. Re: Specify text field format to AAA####
                        LaRetta_1

                        "You would use OnObjectKeystroke ..."

                        Depending upon the FM version Parag is using.