PDA

View Full Version : Regular Expression YYYY-MM-DD and YYYY MM DD



kedibone
2nd July 2010, 11:07
hi, i am a beginner in C++ using Qt4, i need help in writting the regular expression to accept YYYY-MM-DD and YYYY MM DD date formats.

lyuts
2nd July 2010, 11:38
1. Did you try to find it? Here (http://www.regular-expressions.info/dates.html) are some examples. You can modify them.
2. I will assume you are trying to validate user input. If that is true, then take a look at QDateTimeEdit. (http://doc.qt.nokia.com/4.6/qdatetimeedit.html) It should this validation for you.

haneen2017
3rd August 2019, 10:45
1. Did you try to find it? Here (http://www.regular-expressions.info/dates.html) are some examples. You can modify them.
2. I will assume you are trying to validate user input. If that is true, then take a look at QDateTimeEdit. (http://doc.qt.nokia.com/4.6/qdatetimeedit.html) It should this validation for you.


The code below worked for this format, yyyy/MM/ dd i.e 2019/12/02

QRegExp R_date("(19[0-9][0-9]|20[0-9][0-9]) /(0[1-9]|[12]{1,2})/(0[1-9]|[12][0-9]|3[01]{1,2})");
QRegExpValidator *valida = new QRegExpValidator(R_date, this);
ui->lineEdit->setValidator(valida);