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. QRegExp

QRegExp

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 2.7k Views
  • 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.
  • A Offline
    A Offline
    Amarda_4
    wrote on last edited by
    #1

    Please help !!! I'm trying this code for regular expressions,but it always returns false...Any idea ?? Thank You !!
    @if (user.contains(QRegExp("/^[a-z0-9]$/")))
    {
    QMessageBox::information (this, "Validation", "Valide !");}
    else

               {
    
              QMessageBox::warning(this, "Kujdes", "Te dhenat tuaja jane te pasakta.\n Riprovo perseri.");
     }
    

    }@

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Please don't multi-post on the forum.

      What is your input and what are trying to find ?

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

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Amarda_4
        wrote on last edited by
        #3

        I'm sorry about the multi-post.it was accidentally.
        I'm trying to make a check if a user inputs for example characters like !@#$%^ ..it should input just characters and numbers..not other characters..what should I do ?
        Thank You

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          First, have a look at the QRegExp doc, they provide nice examples

          Also note that your test is wrong: your string should be invalid if it contains something else than a-z0-9. In other words: you must search for what it should not contain.

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

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Amarda_4
            wrote on last edited by
            #5

            I've also tried if @(!user.contains(QRegExp("/^[a-z0-9]$/")))@
            But it still doesn't work.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Why do you have these two / ?

              Without them your regexp mean: Start of line, one lower case letter or a number, end of line. Not really what you want.

              You can test and validate your regexp with the regexp example in qt_sources/examples/tools/regexp

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

              1 Reply Last reply
              0
              • A Offline
                A Offline
                Amarda_4
                wrote on last edited by
                #7

                @QRegExp mailREX("^[A-Z0-9]{10}$");@
                This was the right way to work..now it lets me just to enter case letter or a number,with a length of 10 characters..

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  If you want to constrain your user's input, have a look at "QRexExpValidator":http://qt-project.org/doc/qt-4.8/qregexpvalidator.html

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

                  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