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. How to validate string in line edit
Forum Updated to NodeBB v4.3 + New Features

How to validate string in line edit

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.5k Views 1 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.
  • I Offline
    I Offline
    Indrajeet
    wrote on 23 Apr 2013, 05:24 last edited by
    #1

    I want to check if the input string in line edit starts with only alphabet or number.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 23 Apr 2013, 06:30 last edited by
      #2

      Many ways to do this. You can react to QLineEdit::textChanged() or use "QLineEdit::setValidator()":http://qt-project.org/doc/qt-4.8/qlineedit.html#setValidator for example.

      (Z(:^

      1 Reply Last reply
      0
      • B Offline
        B Offline
        b1gsnak3
        wrote on 23 Apr 2013, 08:00 last edited by
        #3

        If you do not want to block the input so that he cannot write anything other than alphabet or number, you could check this with QLineEdit::editingFinished() and if the string is not valid display a message

        1 Reply Last reply
        0
        • I Offline
          I Offline
          Indrajeet
          wrote on 23 Apr 2013, 10:00 last edited by
          #4

          Hi

          I have used setValidator in textChanged() of LineEdit but it is not working consistently.
          First time it works then if i switch to other window and come back then that line edit will allow all characters.

          ui.edit->setValidator(new QRegExpValidator(QRegExp("[a-z0-9]{1}[a-z0-9_-]{0,255}"),NULL));

          What is going wrong?

          1 Reply Last reply
          0

          1/4

          23 Apr 2013, 05:24

          • Login

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