Re: Display only numbers at Last
Dear Wysota,
Thanks for the reply.......Actually i have done the validation something like this.........Just look the code phrased below
Code:
QRegExp rx
("([A-Za-z][A-Za-z][0-9][0-9][A-Za-z][A-Za-z][0-9]+)/([A-Za-z]+)");
ui->lineEditVehicleNumber->setValidator(validator);
qDebug()<<"The Vehicle number is"<<rx;
But actually i am getting the format which i wanted to have numbers at last but im not satisfied with the coding that i have done......Can anyone remodify it......Thanks in Advance......Any solution would be appreciable.
Regards,
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?
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,
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?
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,
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
Quote:
.........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:
Code:
QRegExp rx
("([A][P][1][2][Q][W][1][2][3][4])");
ui->lineEditVehicleNumber->setValidator(validator);
But real, what is your problem right now? QRegExp almost fine, only need some fine tuning.
Re: Display only numbers at Last
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.
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,
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.
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,
Re: Display only numbers at Last
So what is the final expression you came up with?
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.
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.
Code:
bool ok = false;
int num = str.right(4).toInt(&ok);
if( !ok || !num )
{
qDebug() << "Invalid";
}
else
{
qDebug() << "Valid!!" << num;
}
Re: Display only numbers at Last
Quote:
Originally Posted by
nish
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.
Re: Display only numbers at Last
Quote:
Originally Posted by
ChrisW67
Perhaps we are naive to expect that people can define the problem and want to understand why a solution they arrive at works.
The problem is, that programming is a natural skill. You can get better by practice but what i found is that if you dont know it.. you never will. Its just like i cant become a good cricketer no matter how hard i try.
Re: Display only numbers at Last
Dear Forums,
Thanks for the reply.....Actually i have coded in Java for the numbers to display at last for sure................Please find the code for your reference......
Code:
public class test {
public static void main(String[] args) {
String s = "abcd1000231231232131212";
System.out.println(check(s));
}
public static boolean check(String s ) {
if(s.length()>=4){
String s1 = s.substring(s.length()-4, s.length());
System.out.println(s1);
try {
Integer.parseInt(s1);
if(Integer.parseInt(s1) == 0){
return false;
}
return true;
} catch (NumberFormatException e) {
return false;
}
}
return false;
}
}
Please provide me an idea how can it be done in button Event.......Hope you got an idea looking at this.......Any solution would be appreciable.......Thanks in Advance......
Regards
Re: Display only numbers at Last
Well this will be the ported C++ code. Note that exception handling in not required in this case as nothing in this code will raise an exception.
Code:
#include <iostream>
#include <QString>
using namespace std;
{
if(s.length() >= 4)
{
QString s1
= s.
mid(s.
length()-4, s.
length());
cout << s1.toStdString().c_str() << endl;
bool ok = false;
qulonglong Integer = s1.toULongLong(&ok);
if(ok)
{
return true;
}
else
{
return false;
}
}
return false;
}
int main(int argc, char *argv[])
{
QString s
= "abcd1000231231232131212";
cout << check(s) << endl;
}
Re: Display only numbers at Last
Dear Santosh,
Thanks for the reply......Small information that i need it from you is i want the same in the button event if it contains numbers then shld be in the if else format.....Bit confused with the code can you let me know in if-else format ..........Any Solution would be appreciable........Thanks in Advance......
Regards,
Re: Display only numbers at Last
Quote:
Small information that i need it from you is i want the same in the button event ...
I guess you ment button click signal
Quote:
...if it contains numbers then shld be in the if else format...
What is "it"?
Quote:
...Bit confused with the code ...
Please show some code which you are confused with.
Quote:
...can you let me know in if-else format ...
I already gave an example in earlier post.
I suggest start a different thread, as the question is un-related to this threads topic
Re: Display only numbers at Last
Dear Santosh,
Thanks for the reply.......This is my .cpp code please have a look for your reference..........
Code:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QSqlDatabase>
#include <stdio.h>
#include <QTextStream>
#include <QMessageBox>
#include <QSqlRelationalTableModel>
#include <QSqlQuery>
#include <entry.h>
#include <QRegExpValidator>
#include <QLineEdit>
#include <QValidator>
#include <QComboBox>
#include <qdebug.h>
#include <QRegExp>
#include <QValidator>
#include <QRegExpValidator>
#include <QPixmap>
#include <QPalette>
#include <QProcess>
#include <QFile>
#include <Q_INT32>
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui
->lineEditpassword
->setEchoMode
(QLineEdit::Password);
ui->lineEditUsername->setMaxLength(15);
ui->lineEditpassword->setMaxLength(15);
setAutoFillBackground(true);
setPalette(p);
setWindowFlags(Qt::FramelessWindowHint);
}
void MainWindow
::changeEvent(QEvent *e
) {
db.setDatabaseName("/mnt/jffs2/venus.sqlite");
if (!db.open()) {
tr("Unable to establish a database connection.\n"
"This example needs SQLite support. Please read "
"the Qt SQL driver documentation for information how "
}
bool checkquery=query.exec("create table apmc (id INTEGER PRIMARY KEY AUTOINCREMENT,username varchar(20), password password, apmc varchar(20))");
qDebug()<<checkquery;
switch (e->type()) {
ui->retranslateUi(this);
break;
default:
break;
db.close();
}
}
void MainWindow::on_pushButtonLogin_clicked()
{
QString UserName
= ui
->lineEditUsername
->displayText
();
QString Password
= ui
->lineEditpassword
->text
();
QString apmc
=ui
->comboBoxApmc
->currentText
();
qDebug()<<UserName.isEmpty();
qDebug()<<Password.isEmpty();
if(UserName.isEmpty())
{
}
else if(UserName.length()>=4)
{
QString s
= ui
->lineEditUsername
->displayText
();
QString s1
= s.
mid(s.
length()-4, s.
length());
qDebug()<<s1.toStdString().c_str() << "What is the value of s1";
qDebug()<<"The Value of s1 is : "<<s1;
bool ok = false;
qulonglong Integer = s1.toULongLong(&ok);
qDebug()<<"Print for me"<<Integer;
if(ok)
{
qDebug()<<"True";
}
else
{
qDebug()<<"False";
tr
("Please Enter the UserName in right format"),
QMessageBox::Cancel);
ui->lineEditUsername->clear();
ui->lineEditpassword->clear();
}
}
else if(Password.isEmpty())
{
}
else if(apmc=="None")
{
}
else
{
qDebug()<<ui->lineEditUsername->displayText();
bool check=query.exec("insert into apmc (username,password,apmc) values('" + ui->lineEditUsername->displayText() + "','" + ui->lineEditpassword->text() + "' ,'" + ui->comboBoxApmc->currentText()+"')");
qDebug()<<"insertino chekc-----------------"<<check;
msgR->setText("Inserted Successfully");
QPixmap bg
("/home/venugopal/MyQTProjects/G2G/images/G2G.jpg");
setAutoFillBackground(true);
msgR->setPalette(p);
msgR->exec();
this->close();
Entry* e=new Entry();
e->show();
}
}
void MainWindow::on_Delete_clicked()
{
system("rm -Rf /home/venugopal/sample/venu.xml");
}
When i try to perform this action giving only alphabets i am getting the error message that to enter the Username in right format and when i enter the Username with alphabets followed by number its not getting submitted in the button event rather its getting terminated.......Hope you got me........Any Ideas would be appreciable.........Thanks in Advance....
Regards,