Results 1 to 6 of 6

Thread: QRegExp for strings with numbers

  1. #1
    Join Date
    Dec 2014
    Posts
    82
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QRegExp for strings with numbers

    Hi!

    I need a regexp which accepts a string (maximum 30 characters/Slots) with:

    - letters from A to Z (not Á or Ñ or Ë...)
    - numbers
    - spaces
    - signs: . , -

    No matter the order so valid examples are :

    - Hello how are you
    - Hi. My -name- is ... mm

    I was trying with that but it just accepts letters and numbers:
    Qt Code:
    1. QRegExp rx7("[A-Z0-9]{0,30}");
    2. QValidator *validator7 = new QRegExpValidator(rx7, this);
    3. myLineEdit->setValidator(validator7);
    To copy to clipboard, switch view to plain text mode 

    Thank you so much

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QRegExp for strings with numbers

    It only accepts letters and numbers because that's what your regexp contains. You have to put the remaining allowed characters in the selector as well.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Dec 2014
    Posts
    82
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QRegExp for strings with numbers

    Hi wysota,

    Yes I knwo but I don't know how to put dot, coma, spaces and - too. Tried also with that but it accepts too !"··%$&%((/=)**^¨`+
    Qt Code:
    1. QRegExp rx7("[A-Z.- 0-9]{0,30}");
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QRegExp for strings with numbers

    That's because an unescaped dot in a regular expression means "match anything".

    Cheers,
    _

  5. #5
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QRegExp for strings with numbers

    Read about "special characters in regexp". It should looks like :
    Qt Code:
    1. QRegExp rx7("[A-Z\\.\\- 0-9]{0,30}");
    To copy to clipboard, switch view to plain text mode 
    Double backslash derived from the principles of code C / C ++.

  6. #6
    Join Date
    Dec 2014
    Posts
    82
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QRegExp for strings with numbers

    wow didn't know that about dot anda_skoa

    Thanks Lesiok for the clear example You all helped me so much in a moment.

Similar Threads

  1. Unicode strings int Qt 4.2.1
    By mkrentovskiy in forum Qt Programming
    Replies: 12
    Last Post: 29th December 2011, 09:02
  2. Replies: 5
    Last Post: 12th August 2011, 22:55
  3. QRegExp parsing matched quoted strings
    By jhndnn in forum Qt Programming
    Replies: 2
    Last Post: 26th January 2010, 23:05
  4. Replies: 1
    Last Post: 21st September 2009, 07:30
  5. Linguist and static strings
    By Equilibrium in forum Qt Tools
    Replies: 7
    Last Post: 5th March 2008, 13:08

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.