1/*
2 SPDX-FileCopyrightText: 2010 Casey Link <unnamedrambler@gmail.com>
3 SPDX-FileCopyrightText: 2009-2010 Klaralvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "kemailvalidator.h"
8
9#include <KEmailAddress>
10
11KEmailValidator::KEmailValidator(QObject *parent)
12 : QValidator(parent)
13{
14}
15
16KEmailValidator::~KEmailValidator() = default;
17
18QValidator::State KEmailValidator::validate(QString &str, int &pos) const
19{
20 Q_UNUSED(pos)
21
22 if (KEmailAddress::isValidSimpleAddress(aStr: str)) {
23 return QValidator::Acceptable;
24 }
25 const auto containsSpace = std::any_of(first: str.begin(), last: str.end(), pred: [](QChar c) {
26 return c.isSpace();
27 });
28 if (containsSpace) {
29 return QValidator::Invalid;
30 }
31 return QValidator::Intermediate;
32}
33
34void KEmailValidator::fixup(QString &str) const
35{
36 str = str.trimmed();
37}
38
39#include "moc_kemailvalidator.cpp"
40

source code of kcompletion/src/kemailvalidator.cpp