Results 1 to 20 of 46

Thread: Display only numbers at Last

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Display only numbers at Last

    The expression says: "Two letter upper or lower case followed by two digits followed by two letters and at least one digit then the '/' character and any number of lower or upper case letters". Is that what you wanted?
    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.


  2. #2
    Join Date
    Jul 2012
    Location
    Hyderabad
    Posts
    82
    Thanks
    5
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Display only numbers at Last

    Dear Wysota,


    Thanks for the reply......Actually i have written the code in the right way what format i need is "AP12QW1234" the last four what ever we are giving should be numbers.......Thanks in advance.........Any solution would be appreciable.......


    Regards,

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

    Default Re: Display only numbers at Last

    The expression you posted will not match this string. It doesn't have a '/' character anywhere nor does it end with letters. Did you come up with this expression on your own?
    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.


  4. #4
    Join Date
    Jul 2012
    Location
    Hyderabad
    Posts
    82
    Thanks
    5
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Display only numbers at Last

    Dear Wysota,


    Thanks for the reply......yep i have done the validation by myself......Thanks in advance.........Any solution would be appreciable.......


    Regards,

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Display only numbers at Last

    ...and you want us to do what? I must admit I lost your question. You simply what to match AP12QW1234? Then you almost there. Alter the expression, use the web sites mentioned and all is good. If you have precise questions ask them, but
    .........Any solution would be appreciable.......
    wont help you. We will surely do not post c&p code for you.

    To be not cruel a solution can be:
    Qt Code:
    1. QRegExp rx("([A][P][1][2][Q][W][1][2][3][4])");
    2. QValidator *validator = new QRegExpValidator(rx, this);
    3. ui->lineEditVehicleNumber->setValidator(validator);
    To copy to clipboard, switch view to plain text mode 

    But real, what is your problem right now? QRegExp almost fine, only need some fine tuning.

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

    Default Re: Display only numbers at Last

    The solution can also be:

    Qt Code:
    1. QRegExp rx("AP12QW1234");
    To copy to clipboard, switch view to plain text mode 



    @StarRocks:

    This: [A-Z] matches an uppercase letter,
    this: [0-9] matches any single decimal digit.

    To match a particular pattern more than once, repeat it an appropriate number of times, e.g. for matching two uppercase letters you'd use "[A-Z][A-Z]". To match three digits and two letters it would be "[0-9][0-9][0-9][A-Z][A-Z]".

    Now combine those to create a matching pattern for your case. You don't need any parenthesis or pluses or any other extra characters you don't understand and apparently are not willing to understand, just what I have just posted.
    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.


  7. #7
    Join Date
    Jul 2012
    Location
    Hyderabad
    Posts
    82
    Thanks
    5
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Display only numbers at Last

    Dear Lykurg and Wysote,

    Thanks for the reply......Actually don't you think this look very odd "QRegExp rx("([A][P][1][2][Q][W][1][2][3][4])");" or repeating of the same things in the validation...So i thought u would be giving me an idea about how to do not you to do.........Thanks in Advance.........


    Regards,

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

    Default Re: Display only numbers at Last

    First get something that works, then think if it looks odd or not. If you want to match only one string then either compare the input to a string (e.g. if(myText == "APblahblahblah") { ... }) or provide a checkbox for the user instead of the text field to let him mark if he wants to use this particular string or not.
    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.


  9. #9
    Join Date
    Jul 2012
    Location
    Hyderabad
    Posts
    82
    Thanks
    5
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Display only numbers at Last

    Dear Wysota,

    Thanks for the reply......Actually the Vehicle numbers can't be same right it changes according to states so it can't be given a single string,the validation what i have written is working perfectly i just want to know repeating of the same code is a good pro-grammatical manner no i guess..So i thought we would have any other option to do this kind of validation.........Thanks in Advance......


    Regards,

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

    Default Re: Display only numbers at Last

    So what is the final expression you came up with?
    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.


  11. #11
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Display only numbers at Last

    The "validation" you have given us does nothing like what your originally asked for. You started with "INAP1212" and needed to check that there were 4 digits at the right and they were not "0000", then you gave us another example "IN12AP1212" which at least made sense with respect the the earlier requirement. When you gave us your first attempt at coding a validator you had an expression that matched nothing like your example and you were matching against a string containing other random text i.e. "Length: 1212AP". You then "refined" that to an expression that matched things like "Aq34Qr9/junK" or "xX22Xx123456/purpleMonkeyDishwasher" and claimed to be looking to match "AP12QW1234". That these expressions did not match your proposed input strings would have been obvious without coding anything if you used the online tools Wysota and I pointed out. It seems that ultimately your "validation" could be some form of extracting things that could licence plate numbers from within arbitrary text.. but then again maybe not.

    Can you perhaps understand why we have no real idea what you want and little faith that you do either?

    If each of the distinct licence plate patterns can be matched with a regular expression then you can simply store QRegExps in a QMap or QList and use one routine to apply the appropriate regular expression (or all of them). This might be as simple as one expression per state, or it might not, we do not know. If the patterns cannot be matched by a regular expression (it is possible) then you may need a list of validator functions/function objects each doing a complex check.

  12. #12
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Display only numbers at Last

    Dear StarRocks,

    Topics like these really sinks Indian reputation around the web.
    All though senior people here will not appreciate my post but I think OP is not going to get the RegExp thing correctly implemented.

    I will take the problem in the first post.

    This should be enough for most Strings. You do need some extra checks for length.
    Qt Code:
    1. QString str = "IN12AP1212";
    2.  
    3. bool ok = false;
    4. int num = str.right(4).toInt(&ok);
    5.  
    6. if( !ok || !num )
    7. {
    8. qDebug() << "Invalid";
    9. }
    10. else
    11. {
    12. qDebug() << "Valid!!" << num;
    13. }
    To copy to clipboard, switch view to plain text mode 

  13. #13
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Display only numbers at Last

    Quote Originally Posted by nish View Post
    All though senior people here will not appreciate my post but I think OP is not going to get the RegExp thing correctly implemented.
    I think people around here, including you, have spent more than enough time on this. Perhaps we are naive to expect that people can define the problem and want to understand why a solution they arrive at works.
    "We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
    If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.

Similar Threads

  1. Replies: 2
    Last Post: 26th January 2012, 15:31
  2. How to display the numbers in a QList<QString> ?
    By harish in forum Qt Programming
    Replies: 4
    Last Post: 3rd January 2012, 04:26
  3. Replies: 1
    Last Post: 18th June 2011, 18:28
  4. Replies: 3
    Last Post: 17th April 2010, 21:35
  5. How to use QLCDnumber to display negative numbers?
    By grissiom in forum Qt Programming
    Replies: 1
    Last Post: 19th March 2010, 06:23

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
  •  
Qt is a trademark of The Qt Company.