[SOLVED] Validate e-mail with QRegularExpression



  • Hello!

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

    I am trying with me@me.com 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");
    
    if(!regex.match(email).hasMatch())
    {
        retorno = false;
    }
    
    return retorno;
    

    }
    @

    Whats is going wrong?

    Thanks in advance.



  • Solved

    [CODE]
    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}$");
    [/CODE]


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.