Results 1 to 3 of 3

Thread: Validate e-mail with QRegularExpression

  1. #1
    Join Date
    Feb 2014
    Posts
    94
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default 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

    Qt Code:
    1. bool regExpressionRetorno::validaEmail(QString email)
    2. {
    3. bool retorno = true;
    4.  
    5. qDebug() << email;
    6.  
    7. QRegularExpression regex("\\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}\\b");
    8.  
    9. if(!regex.match(email).hasMatch())
    10. {
    11. retorno = false;
    12. }
    13.  
    14. return retorno;
    15. }
    To copy to clipboard, switch view to plain text mode 

    Whats is going wrong?

    Thanks in advance.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Validate e-mail with QRegularExpression

    Your regular expression will only match uppercase letters. Reread the description of this RE http://www.regular-expressions.info/email.html. Take a look at the other parameters to the QRegularExpression constructor.

  3. #3
    Join Date
    Feb 2014
    Posts
    94
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Validate e-mail with QRegularExpression

    Solved

    Qt Code:
    1. 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}$");
    To copy to clipboard, switch view to plain text mode 

    Thanks for the reply ChrisW67

Similar Threads

  1. QRegularExpression question
    By vycke in forum Qt Programming
    Replies: 5
    Last Post: 13th February 2015, 04:42
  2. Validate TextField
    By porterneon in forum Qt Quick
    Replies: 0
    Last Post: 12th November 2014, 14:57
  3. Replies: 1
    Last Post: 17th October 2013, 14:30
  4. How to validate a form?
    By homerun4711 in forum Newbie
    Replies: 8
    Last Post: 28th February 2011, 18:47
  5. How to validate XML against DTD?
    By emental86 in forum Qt Programming
    Replies: 2
    Last Post: 29th April 2009, 13:11

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.