Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Validate IP address or hostname with port & range check with RegExpValidator
Forum Updated to NodeBB v4.3 + New Features

Validate IP address or hostname with port & range check with RegExpValidator

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 1.9k 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.
  • E Offline
    E Offline
    esther
    wrote on 2 Jan 2018, 06:12 last edited by A Former User 1 Mar 2018, 18:01
    #1

    QT 5.9.2 … Android

    ^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3})(:\d{1,5})$|^((([a-zA-Z]|[a-zA-Z0-9][a-zA-Z0-9-][a-zA-Z0-9]).)([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9-][A-Za-z0-9]))(:\d{1,5})*$

    FoobarHost
    FoobarHost:12345
    Ip
    Ip:12345

    Works with online reg tester https://regex101.com with /m multiline option but not with QT Qml … is there a way to validate ip and hostname

    TextField {
    id: serverIpText
    height: 24
    maximumLength: 255
    cursorVisible: true
    // DNS allows alphanumeric and hyphens... dots are in IP address... and : separates optional port number
    //
    validator: RegExpValidator {
    regExp: /^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3})(:\d{1,5})$|^((([a-zA-Z]|[a-zA-Z0-9][a-zA-Z0-9-][a-zA-Z0-9]).)([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9-][A-Za-z0-9]))(:\d{1,5})*$/
    }
    }

    1 Reply Last reply
    0
    • E Offline
      E Offline
      Ebrahim Karimi
      wrote on 1 Sept 2023, 23:07 last edited by Ebrahim Karimi 9 Apr 2023, 15:38
      #2

      I know its an old topic but it was the first search result so im gonna post my solution

      your regex is wrong and when you try to test a regex on regex101 dont forget to select your programming language.

      here is a working regex which allows you to extract ip address or hostname

      ^(?<qfdn>^[a-zA-Z]+.+\\.{1}[a-zA-Z]{2,}$)|(?<ip>^(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d){1}$)$
      

      this works on javascript so i think qml too

      Standing on the shoulder of the giants

      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