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?
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?
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,
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?
Dear Wysota,
Thanks for the reply......yep i have done the validation by myself......Thanks in advance.........Any solution would be appreciable.......
Regards,
...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, butwont help you. We will surely do not post c&p code for you..........Any solution would be appreciable.......
To be not cruel a solution can be:Qt Code:
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.
The solution can also be:
@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.
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,
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.
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,
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.
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:
bool ok = false; int num = str.right(4).toInt(&ok); if( !ok || !num ) { qDebug() << "Invalid"; } else { qDebug() << "Valid!!" << num; }To copy to clipboard, switch view to plain text mode
"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.
Bookmarks