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. IP Validation on QlineEdit

IP Validation on QlineEdit

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 6.1k 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.
  • Pranit PatilP Offline
    Pranit PatilP Offline
    Pranit Patil
    wrote on last edited by Pranit Patil
    #1

    I have 5 Qline Edit which accept diff diff Ip address and one push button.
    whenever i clicked pushButton i want to verify QlineEdit text is correct or not (with ip validator)

    QString IpRange = "(?:[0-1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])";
    QRegExp IpRegex ("^" + IpRange
    + "(\." + IpRange + ")?"
    + "(\." + IpRange + ")?"
    + "(\." + IpRange + ")?$");
    QRegExpValidator *ipValidator = new QRegExpValidator(IpRegex, this);

    uiPoMo->lineEdit_ServerIP_2->setValidator(ipValidator);
    

    I used this validation But when i entered only 1 integer it was accept how? its not proper working?

    if(false == uiPoMo->lineEdit_ServerIP_2->hasAcceptableInput())
    {
    QMessageBox::warning(this,"Waring!"," not valid");
    }
    else
    {
    QMessageBox::warning(this,"Waring!"," valid");
    }

    When Pushbutton pressed this code Execte but not work properly?
    can any one Help Me ?

    Thank You.

    @Embedded Software Developer
    God has given you one face, and you make yourself another.

    JonBJ 1 Reply Last reply
    0
    • Pranit PatilP Pranit Patil

      I have 5 Qline Edit which accept diff diff Ip address and one push button.
      whenever i clicked pushButton i want to verify QlineEdit text is correct or not (with ip validator)

      QString IpRange = "(?:[0-1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])";
      QRegExp IpRegex ("^" + IpRange
      + "(\." + IpRange + ")?"
      + "(\." + IpRange + ")?"
      + "(\." + IpRange + ")?$");
      QRegExpValidator *ipValidator = new QRegExpValidator(IpRegex, this);

      uiPoMo->lineEdit_ServerIP_2->setValidator(ipValidator);
      

      I used this validation But when i entered only 1 integer it was accept how? its not proper working?

      if(false == uiPoMo->lineEdit_ServerIP_2->hasAcceptableInput())
      {
      QMessageBox::warning(this,"Waring!"," not valid");
      }
      else
      {
      QMessageBox::warning(this,"Waring!"," valid");
      }

      When Pushbutton pressed this code Execte but not work properly?
      can any one Help Me ?

      Thank You.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Pranit-Patil
      This may or may not solve you problem, but:

      "(\."

      In a C++ literal string, don't you mean:

      "(\\."

      ?

      1 Reply Last reply
      2
      • KillerSmathK Offline
        KillerSmathK Offline
        KillerSmath
        wrote on last edited by KillerSmath
        #3

        @Pranit-Patil Hi there.

        Like @jonB says above, you should to replace\.to\\.to avoid an error of escape caracter.

        But if you want to validate just if the user insert the complete ip, you must to remove the "optional counter caracter" of each group of numbers.

        Example:

        "(\\." + IpRange + ")?"
        

        this sentence accepts:
        (void) and 0 until 255 number because of ? caracter that means: 0 or 1 time

        NOTE: QRegExp is an old class of Qt4, if you are using Qt5+, i suggest you to use QRegularExpression

        Below is a code solving the problems:

            QString IpRange = "(?:[0-1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])";
            QRegularExpression IpRegex ("^" + IpRange
                                        + "(\\." + IpRange + ")"
                                        + "(\\." + IpRange + ")"
                                        + "(\\." + IpRange + ")$");
            QRegularExpressionValidator *ipValidator = new QRegularExpressionValidator(IpRegex, this);
        

        @Computer Science Student - Brazil
        Web Developer and Researcher
        “Sometimes it’s the people no one imagines anything of who do the things that no one can imagine.” - Alan Turing

        1 Reply Last reply
        6
        • Pranit PatilP Offline
          Pranit PatilP Offline
          Pranit Patil
          wrote on last edited by
          #4

          Thank you for your guidlines.
          yesterday only i solved my Problem

          Thank You.

          @Embedded Software Developer
          God has given you one face, and you make yourself another.

          1 Reply Last reply
          1

          • Login

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