Display only numbers at Last
Dear Forums,
I have small doubt in QT..... Guys i have Vehicle number as INAP1212 now what i need is each and everytime the last four should always be digits and should not be 0000.............I need a validation for it.........Can anyone make it out for me...........Any solution would be appreciable....
Regards,
Venugopal.T
Re: Display only numbers at Last
Quote:
Originally Posted by
StarRocks
Dear Forums,
I have small doubt in QT..... Guys i have Vehicle number as INAP1212 now what i need is each and everytime the last four should always be digits and should not be 0000.............I need a validation for it.........Can anyone make it out for me...........Any solution would be appreciable....
Regards,
Venugopal.T
I am sorry if it sounds condescending, but you need to understand how this forum works. You have been opening several new topics recently, in which you always ask someone to solve a problem for you, without showing that you actually tried anything on your own. Guess what: the people who help each other here do so for free, in their free time. They will only help you solve your problem, not do it for you. If you are looking for someone to do your work for you, just hire some seasoned Qt developer.
I suggest you try harder, explain what you have tried; I am confident that someone will then help you.
Re: Display only numbers at Last
Quote:
I have small doubt in QT..... Guys i have Vehicle number as INAP1212 now what i need is each and everytime the last four should always be digits and should not be 0000.............I need a validation for it.........Can anyone make it out for me...........Any solution would be appreciable....
You don't explain anything about how or where you want to do this validation. So, if you are trying to validate input into a QLineEdit widget, then I suggest you read about QValidator, QRegExp, and QRegExpValidator. Those classes will allow you to write a validator for the problem you have described.
And like yeye_olive says, don't simply reply with "OK, give me example code for that". Try it on your own, and if you still can't solve it, post your code and ask what you are doing wrong.
Re: Display only numbers at Last
Hi Guys,
Thanks for your feedback.........Listen i have posted few queries which i solved by my own noone gave any solutions.......First have a look at my queries im posting queries which i tried a lot and only then im posting to my knowledge that queries are not that easy to solve i guess.........Im not jus posting without trying sorry if i hurt u guys.........
Regards,
Re: Display only numbers at Last
Quote:
I have small doubt in QT..... Guys i have Vehicle number as INAP1212 now what i need is each and everytime the last four should always be digits and should not be 0000.............I need a validation for it.........Can anyone make it out for me...........Any solution would be appreciable....
@StarRocks: Look at what you said here. You did not say anything at all about having tried something. You didn't post any code and ask "Why doesn't this work"? You just said "Here's my problem. Tell me the answer".
So when you post something like that, what are we supposed to think? Next time, tell us what you've tried and what didn't work so we can at least tell that you aren't just begging for free answers. You will be much more likely to get some help instead of abuse in that case.
Re: Display only numbers at Last
Dear d_stranz,
Its not like im begging for answers and all..............Please understand that first and i have written a code in Javascript and its working for me but i cant implement the same for C++ right....
As im new to Qt so i want to know how to use that coz its only validation prob ...........For ur reference the below is the code...
function ValidateVehicleNumber(strVarInstance) {
var strResult = "";
var cnt = 0;
var count1 = 0;
if (strVarInstance[1] == '') {
cnt++;
strResult += "";
}
else {
var VehicleNo = strVarInstance[1];
if (VehicleNo.length < 4) {
cnt++;
strResult += "Vehicle Number contains Atleast four digits \n ";
}
else {
var index = VehicleNo.length - 4
var count = 0;
for (i = index; i < VehicleNo.length; i++)
{
var c = VehicleNo.charAt(i);
if (isNaN(c) || c == " " )
{
count++;
}
if (c == 0) {
count1++;
}
}
if (count != 0)
{
cnt++;
strResult += "Last four character of Vehicle Number digits only \n ";
}
if (count1 == 4) {
cnt++;
strResult += "Vehicle Number should not be zeros \n ";
}
}
}
return strResult;
}
Regards
Re: Display only numbers at Last
In order to port this code as-is to Qt you need to do the following (in this order):
1. learn C++;
2. learn some Qt basics;
3. have a look at the documentation for the QString and QChar classes, that you will use to represent strings and characters respectively. All the operations you need are there.
However you can probably replace all this code with a simple regular expression. Once you have done steps 1 and 2 above, you can have a look at QRegExp, which d_stranz mentioned above. The documentation of the class explains the syntax of regular expressions and gives some examples that among other things show how to match digits in a string.
Display only numbers at Last
Dear Forums,
Thanks for the reply .......Will go through the things that you asked me to if any doubts will contact you..........
Regards,
Re: Display only numbers at Last
Dear Forums,
As i have posted previously too i have google searched validations for everything i have got most of them but except the one im searching for i.e having numbers at the last i have tried but achieved only in having something like this as "ap12" but i have to get only numbers after that....Hope you got me......example is IN12AP1212.........Thanks in Advance.......Any solution would be appreciable.....
Regards,
Re: Display only numbers at Last
Have you tried to check the strings with a regular expression? See QRegularExpression.
Re: Display only numbers at Last
Dear Lykurg,
Thanks for the reply....I have gone through the QRegularExpression but dint find any solution through that so posted in the forums again......Any solution would be appreciable.......
Regards,
Re: Display only numbers at Last
Open the QRegularExpression documentation again and instead of looking for a solution there, read the documentation with understanding.
Re: Display only numbers at Last
Dear Wysota,
Thanks for the reply........I have read the documentation i have used most of the syntax in my application but not finding the required....Its not that i have only looked for the solution have even read the docs........Any solution would be appreciable......Thanks in Advance........
Regards,
Re: Display only numbers at Last
Show us what you have tried to do with those classes rather than just telling us that you have "used most of the syntax in my application" or that you "have even read the docs". We cannot fix or guide based on what we cannot see.
This is how you show us. Copy the following two lines into a reply:
[code]
[/code]
Then, between the two tags, paste your best attempt at coding the function to validate the input and press Submit Reply.
The solution can be had using only the classes pointed out in this thread. I estimate an equivalent of your script routine consists of less than twenty lines. That depends a little on exactly what "strVarInstance" represents because the script code is, well, odd.
Re: Display only numbers at Last
Dear Chris,
Thanks for the reply......Please find the below code about how i used one of the syntax for my application.........
Code:
QRegExp rxlen
("(\\d+)(?:\\s*)([0-9]|[A-Z])");
int pos = rxlen.indexIn("Length: 1212AP");
if (pos > -1) {
QString value
= rxlen.
cap(1);
// "189" QString unit
= rxlen.
cap(2);
// "cm"
qDebug()<<value<<"The Value is";
qDebug()<<unit<<"The Unit is";
qDebug()<<uts<<"The Uts is";
Thanks in Advance.....Any solution would be appreciable........
Regards,
Re: Display only numbers at Last
Your expression reads: one or more digits followed by a 0 or more white spaces followed by a digit or capital letter. There is no cap(3) here. Did you really think this expression would match a string such as "INAP1212"?
Quote:
Originally Posted by StarRocks
Guys i have Vehicle number as INAP1212 now what i need is each and everytime the last four should always be digits and should not be 0000
Re: Display only numbers at Last
Dear Wysota,
Thanks for the reply......Actually in my code i have commented that line but forgot to do the same in the coding that i have posted........Hope you understood the situation that i have posted.........Any solution would be appreciable.......Thanks in Advance...Actually i am not exactly knowing how to have syntax in that format...
Regards,
Re: Display only numbers at Last
So what expression did you code if it wasn't the one you posted?
Re: Display only numbers at Last
Concentrate on getting a regular expression that matches 4 or more digits. Once you have that extend it by forcing the match to only occur at the end of the string and you will be most of the way there. You may find an online regular expression tester a useful tool to help learn in conjunction with the Qt docs.
Re: Display only numbers at Last