Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. line edit validator number regex
Qt 6.11 is out! See what's new in the release blog

line edit validator number regex

Scheduled Pinned Locked Moved Solved General and Desktop
19 Posts 4 Posters 2.7k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #9

    You also have the regular expression tool that you can build and will give you the exact string you need in your code.

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    JonBJ 1 Reply Last reply
    3
    • SGaistS SGaist

      You also have the regular expression tool that you can build and will give you the exact string you need in your code.

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by
      #10

      @SGaist
      Excellent. But @user4592357 will probably have to return to his computer to achieve that :)

      1 Reply Last reply
      0
      • U Offline
        U Offline
        user4592357
        wrote on last edited by
        #11

        @SGaist @JonB
        thanks for all info.
        unfortunately, ^((\d+|\d+-\d+) *)+$ regex still allows hyphen after 5-555.
        i just need to regexp validator for my input, nothing to match for now.

        JonBJ 1 Reply Last reply
        0
        • U user4592357

          @SGaist @JonB
          thanks for all info.
          unfortunately, ^((\d+|\d+-\d+) *)+$ regex still allows hyphen after 5-555.
          i just need to regexp validator for my input, nothing to match for now.

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by
          #12

          @user4592357 said in line edit validator number regex:

          unfortunately, ^((\d+|\d+-\d+) *)+$ regex still allows hyphen after 5-555.

          Pardon?
          5-555- gives Your regular expression does not match the subject string..

          Instead of making us guess what input you have in mind, could you please test with one of the reg ex validators we referenced and paste precisely what string you claim it does/does not match?

          ODБOïO 1 Reply Last reply
          0
          • JonBJ JonB

            @user4592357 said in line edit validator number regex:

            unfortunately, ^((\d+|\d+-\d+) *)+$ regex still allows hyphen after 5-555.

            Pardon?
            5-555- gives Your regular expression does not match the subject string..

            Instead of making us guess what input you have in mind, could you please test with one of the reg ex validators we referenced and paste precisely what string you claim it does/does not match?

            ODБOïO Offline
            ODБOïO Offline
            ODБOï
            wrote on last edited by
            #13

            hi
            @JonB said in line edit validator number regex:

            5-555- gives Your regular expression does not match the subject string..

            If you write another number after the "5-555-" , then it will be accepted, ex : 5-555-8
            OP only wants to accept groupes of 2 numbers separated by a hyphen.

            JonBJ 1 Reply Last reply
            1
            • ODБOïO ODБOï

              hi
              @JonB said in line edit validator number regex:

              5-555- gives Your regular expression does not match the subject string..

              If you write another number after the "5-555-" , then it will be accepted, ex : 5-555-8
              OP only wants to accept groupes of 2 numbers separated by a hyphen.

              JonBJ Online
              JonBJ Online
              JonB
              wrote on last edited by JonB
              #14

              @LeLev
              Then I wish he had said so and given such an example, instead of

              still allows hyphen after 5-555.

              I will look at this now and offer an alternative in a few minutes time...
              ...like either of:

              ^((\d+|\d+-\d+)\b *)+$
              
              ^(\d+(-\d+)?\b *)+$
              
              U 1 Reply Last reply
              2
              • JonBJ JonB

                @LeLev
                Then I wish he had said so and given such an example, instead of

                still allows hyphen after 5-555.

                I will look at this now and offer an alternative in a few minutes time...
                ...like either of:

                ^((\d+|\d+-\d+)\b *)+$
                
                ^(\d+(-\d+)?\b *)+$
                
                U Offline
                U Offline
                user4592357
                wrote on last edited by user4592357
                #15

                @JonB
                thanks!
                anyways, i wanna understand why the regex with \b allows 55-555-? how does it match/validate?
                because for that same string, the line edit's hasAcceptableInput() returns false.

                JonBJ 1 Reply Last reply
                0
                • U user4592357

                  @JonB
                  thanks!
                  anyways, i wanna understand why the regex with \b allows 55-555-? how does it match/validate?
                  because for that same string, the line edit's hasAcceptableInput() returns false.

                  JonBJ Online
                  JonBJ Online
                  JonB
                  wrote on last edited by
                  #16

                  @user4592357

                  anyways, i wanna understand why the regex with \b allows 55-555-? how does it match/validate?

                  Neither of the two regexs I have given with \b allow 55-555-. As tested at rex101.com.

                  I am finding your questions/statements very hard to comprehend....

                  U 1 Reply Last reply
                  0
                  • JonBJ JonB

                    @user4592357

                    anyways, i wanna understand why the regex with \b allows 55-555-? how does it match/validate?

                    Neither of the two regexs I have given with \b allow 55-555-. As tested at rex101.com.

                    I am finding your questions/statements very hard to comprehend....

                    U Offline
                    U Offline
                    user4592357
                    wrote on last edited by
                    #17

                    @JonB
                    sorry, i mean with previous (((\d+|\d+-\d+) *)+) regex, the validator allowed 55-555-.
                    which part of the regex string did match with the hyphen after 55-555? i want to understand the logic for matching it.

                    JonBJ 1 Reply Last reply
                    0
                    • U user4592357

                      @JonB
                      sorry, i mean with previous (((\d+|\d+-\d+) *)+) regex, the validator allowed 55-555-.
                      which part of the regex string did match with the hyphen after 55-555? i want to understand the logic for matching it.

                      JonBJ Online
                      JonBJ Online
                      JonB
                      wrote on last edited by
                      #18

                      @user4592357
                      So when you said

                      why the regex with \b allows

                      you meant

                      why the regex without \b allows

                      ! :)

                      Regex: ^((\d+|\d+-\d+) *)+$
                      Input: 5-555-8

                      You want to know why the input does match here. That's because in order to force a match if it possibly can, which is how reg exs work, this gets treated as though it were:
                      5-55 5-8
                      i.e. two separate digits-digits sequences. So I put in the \b word-boundary token in ^((\d+|\d+-\d+)\b *)+$ to prevent it splitting in the middle of a sequence of consecutive digits.

                      U 1 Reply Last reply
                      3
                      • JonBJ JonB

                        @user4592357
                        So when you said

                        why the regex with \b allows

                        you meant

                        why the regex without \b allows

                        ! :)

                        Regex: ^((\d+|\d+-\d+) *)+$
                        Input: 5-555-8

                        You want to know why the input does match here. That's because in order to force a match if it possibly can, which is how reg exs work, this gets treated as though it were:
                        5-55 5-8
                        i.e. two separate digits-digits sequences. So I put in the \b word-boundary token in ^((\d+|\d+-\d+)\b *)+$ to prevent it splitting in the middle of a sequence of consecutive digits.

                        U Offline
                        U Offline
                        user4592357
                        wrote on last edited by
                        #19

                        @JonB
                        ok got it, thanks for explanation!

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved