Regular Expression for QDate [YYYY/MM/DD] format
Hi,
I have a line edit which takes user input and stores it in a QDATE object in [YYYY/MM/DD] format. I want to construct a regular expression for this. and then use the QValidator to validate the user input against this expression.
It would be helpful if you could give me a regular expression to validate QTIME [HH:MM:SS] for the same purpose.
please help me out.
Regards,
BERA
Re: Regular Expression for QDate [YYYY/MM/DD] format
For date try something like that
Code:
QRegExp reDate
("[0-9]{0,4}/[0-9]{0,2}/[0-9]{0,2}");
Re: Regular Expression for QDate [YYYY/MM/DD] format
Maybe an input mask would be enough? If not, the easiest regexp validator for yyyy/mm/dd would be [12][0-9][0-9][0-9]/[01][0-9]/[0-3][0-9]. For time: [0-2][0-9]:[0-5][0-9]:[0-5][0-9]. Of course you can make them more complex so that dates like 2006-02-31 are not possible to enter. But it would probably be best to make a QDate based validator - subclass QValidator and reimplement validate() and fixup().
Re: Regular Expression for QDate [YYYY/MM/DD] format
What about using QDateTimeEdit?
Re: Regular Expression for QDate [YYYY/MM/DD] format
Hi,
I had used DateTimeEdit but the date format is not the way i need it. I need the date parameters as integers so that i can perform calculations. DateTimeEdit returns date as 11Mar2006! I tried to convert by applying the parameter "Qt::ISODate" but this parameter can be passed only for the "::fromString()" function !!
Thanks,
Regards,
Bera.
Re: Regular Expression for QDate [YYYY/MM/DD] format
Quote:
Originally Posted by bera82
DateTimeEdit returns date as 11Mar2006! I tried to convert by applying the parameter "Qt::ISODate" but this parameter can be passed only for the "::fromString()" function !!
What about QDateTimeEdit::date(), QDateTimeEdit::dateTime() and QDateTimeEdit::time()?
Re: Regular Expression for QDate [YYYY/MM/DD] format
Quote:
Originally Posted by
jacek
The code below worked for this format, d/M/yyyy i.e 1/12/2019
Code:
QRegExp R_date
("([1-9]|[12][0-9]|3[01]{1,2})/([1-9]|[12]{1,2})/(19[0-9][0-9]|20[0-9][0-9])");
ui->lineEdit->setValidator(valida);
The code below worked for this format, dd/MM/yyyy i.e 01/12/2019, 02/03/2019
Code:
QRegExp R_date
("(0[1-9]|[12][0-9]|3[01]{1,2})/(0[1-9]|[12]{1,2})/(19[0-9][0-9]|20[0-9][0-9])");
ui->lineEdit->setValidator(valida);