how do i limit user choice to three options?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #16
    To limit it to 0-100, change it from any number of digits to any 2 digit number or 100.

    Comment

    • NellievD
      New Member
      • Oct 2014
      • 14

      #17
      I have decided to work with this approach for what I need to accomplish:

      On change*
      // Test input in real time. Only allow approved grades, r, i, n with the code on exit replacing n with na
      if (xfa.event.chan ge!="" && !xfa.event.newT ext.match(/^[0-9]+?$|^(^n?)?$|^( r)?$|^(i)?$/)) {
      xfa.event.chang e ="";
      xfa.host.messag eBox("Oops, incorrect entry, Please correct your input. Thank you.");
      }

      Then on exit*
      this.rawValue=t his.rawValue.re place(/n/g,"NA")
      this.rawValue=t his.rawValue.to UpperCase()

      The user is restricted to entering the three options "r", "i", or "n" where "n" is replaced by "na" on exit and all the values are also uppercased. The digits are limited to 3 by virtue of the field length limit.
      I have no idea how to limit the number entries from 001 to 100, so that is unfortunate. I'm still open to some help on this! Thanks for all the input...

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #18
        001-100? Or 1-100? They're different. If the former, limit the first digit to 0 and 1, and the next 2 digits to any number. If the latter, use the method I described in post #16

        Comment

        • NellievD
          New Member
          • Oct 2014
          • 14

          #19
          OK, good idea! But where do I find post #16. I looked, I promise!

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #20
            This post is 20, look up 4 posts.

            Comment

            • NellievD
              New Member
              • Oct 2014
              • 14

              #21
              How does this look? (I'm still getting an error when i input three digits like "560:...)
              On change*
              //Test input in real time. Only allow approved grades, r, i, na
              if (xfa.this.chang e!="" && !xfa.event.newT ext.match(/^([1-9]{1,2}[0]?|100+|n|r|i)$/)) {
              xfa.event.chang e ="";
              xfa.host.messag eBox("Incorrect entry.. also, n outputs NA. Thanks!");
              }

              On exit*
              this.rawValue=t his.rawValue.re place(/n/g,"NA")
              this.rawValue=t his.rawValue.to UpperCase()
              Last edited by NellievD; Oct 16 '14, 01:01 AM. Reason: correction re notation

              Comment

              • NellievD
                New Member
                • Oct 2014
                • 14

                #22
                Hello Rabbit,
                I've amended the regex for the number entry:

                //Test input in real time. Only allow approved grades, r, i, na
                if (xfa.this.chang e!="" && !xfa.event.newT ext.match(/^[1-9][0-9]?$|^100|^(n?)?$ |^(r)?$|^(i)?$/)){
                xfa.event.chang e ="";
                xfa.host.messag eBox("Incorrect entry.. also, n outputs NA. Thanks!");
                }

                On exit*
                this.rawValue=t his.rawValue.re place(/n/g,"NA")
                this.rawValue=t his.rawValue.to UpperCase()

                I think this time I've got it...

                Comment

                • Rabbit
                  Recognized Expert MVP
                  • Jan 2007
                  • 12517

                  #23
                  Your first attempt is closer, your second one has a bunch of extra stuff for some reason, even on stuff that was working fine before.

                  Take the first attempt and fix that one. For example, your piece with the 100, you have a plus sign in there for some reason, that tells the expression to match as many zeroes as possible.

                  And for the piece that defines any two digit number, for some reason you tell it can have an optional zero at the end.

                  Comment

                  • NellievD
                    New Member
                    • Oct 2014
                    • 14

                    #24
                    You're right: messy code! How about this? It tests fine inside Livecycle ...

                    On change*

                    if (xfa.this.chang e!="" && !xfa.event.newT ext.match(/^[1-9][0-9]?$|^100|^(n|r|i )$/)){
                    xfa.event.chang e ="";
                    xfa.host.messag eBox("Incorrect entry.. also, n outputs NA. Thanks!");
                    }

                    On exit*
                    this.rawValue=t his.rawValue.re place(/n/g,"NA")
                    this.rawValue=t his.rawValue.to UpperCase()

                    Comment

                    • Rabbit
                      Recognized Expert MVP
                      • Jan 2007
                      • 12517

                      #25
                      If it's testing fine then it's correct. But it can be cleaned up a little.
                      Code:
                      /^([1-9][0-9]?|100|n|r|i)$/

                      Comment

                      • NellievD
                        New Member
                        • Oct 2014
                        • 14

                        #26
                        Thanks so much for sticking with me on this. Your code got rid of the some of the extraneous stuff, and works properly! Thanks again for the help.

                        Comment

                        • Rabbit
                          Recognized Expert MVP
                          • Jan 2007
                          • 12517

                          #27
                          No problem, good luck with the rest of your project.

                          Comment

                          Working...