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. [SOLVED] Use RegExpValidator to validate strings
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Use RegExpValidator to validate strings

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 1.1k 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.
  • P Offline
    P Offline
    Per-Erik Kristensson
    wrote on last edited by
    #1

    I want to check if a string is valid with regular expression. I have found the RegExpValidator object, but only with sample where a TextInput is used. How do I use this to just validate a string? I want to have something like this:

    @
    RegExpValidator
    {
    id: regexpValidator;
    regExp: /[0-9]+/
    }

    function test()
    {
        var textIsValid = regexpValidator.regExp.validate("Hello world!", 0);
    }
    

    @

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

      Hi,

      Use the regexp directly:

      @
      function test()
      {
      var regExp = /[0-9]+/;
      var textIsValid = regExp.test("Hello world!");
      }
      @

      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
      • P Offline
        P Offline
        Per-Erik Kristensson
        wrote on last edited by
        #3

        Oh… that was simple! Thanks! :-)

        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