1/*
2 Copyright (C) 2010 Casey Link <unnamedrambler@gmail.com>
3 Copyright (C) 2009-2010 Klaralvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
4
5 This library is free software; you can redistribute it and/or modify it
6 under the terms of the GNU Library General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or (at your
8 option) any later version.
9
10 This library is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 02110-1301, USA.
19*/
20
21#include "emailvalidator.h"
22#include "email.h"
23
24using namespace KPIMUtils;
25
26EmailValidator::EmailValidator( QObject *parent ) : QValidator( parent )
27{
28}
29
30QValidator::State EmailValidator::validate( QString &str, int &pos ) const
31{
32 Q_UNUSED( pos );
33
34 if ( KPIMUtils::isValidSimpleAddress( str ) ) {
35 return QValidator::Acceptable;
36 }
37
38 // we'll say any string that doesn't have whitespace
39 // is an intermediate email string
40 if ( QRegExp( QLatin1String("\\s") ).indexIn( str ) > -1 ) {
41 return QValidator::Invalid;
42 }
43
44 return QValidator::Intermediate;
45}
46
47void EmailValidator::fixup( QString &str ) const
48{
49 str = str.trimmed();
50}
51