I'm trying to use regex to validate email and phone fields (the fields are QLineEdit
).
I'm using the following example:
QString expression = "[1-9]\\d{0,3}";
QRegularExpression rx(expression);
QValidator *validator = new QRegularExpressionValidator(rx, this);
QLineEdit *edit = new QLineEdit(this);
edit->setValidator(validator);
I'm using the following expressions to validate it:
const QString Phone = "/^\+?(\d.*){3,}$/";
const QString Email = "/^.+@.+$/";
These expressions were obtained from this web site: https://projects.lukehaas.me/regexhub/
But it does not work as expected, since it is 'blocking' any input to the email and phone fields.
What regular expressions should I use to validate these fields?
Note that I don't need a much precise validation. I need basically this:
Email: any content, an @ mark, any content, dot, any content. For example: user@email.com or user_123@email.com.br
Phone: any number and the following characters ")(+- ".