Important: Please read the Qt Code of Conduct -

[SOLVED] Validate e-mail with QRegularExpression

  • Hello!

    I am having a problem to validate an e-mail with QRegularExpression.

    I am trying with an it returns false

    bool regExpressionRetorno::validaEmail(QString email)
    bool retorno = true;

    qDebug() << email;
    QRegularExpression regex("\\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}\\b");
        retorno = false;
    return retorno;


    Whats is going wrong?

    Thanks in advance.

  • Solved

    QRegularExpression regex("^[0-9a-zA-Z]+([0-9a-zA-Z][-._+])[0-9a-zA-Z]+@[0-9a-zA-Z]+([-.][0-9a-zA-Z]+)([0-9a-zA-Z][.])[a-zA-Z]{2,6}$");

Log in to reply