Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 2cfe6214

Von Christian Ehringfeld vor mehr als 9 Jahren hinzugefügt

  • ID 2cfe6214625343a15d743c9c882fc75340ca33d9
  • Vorgänger 93bf6dcb
  • Nachfolger 34233707

email validator

Unterschiede anzeigen:

src/validators/emailvalidator.cpp
#include "emailvalidator.h"
#include <QRegularExpression>
using namespace CuteEntityManager;
EmailValidator::EmailValidator() : Validator() {
}
ErrorMsg EmailValidator::validateParam(QVariant value, Param param) const {
QRegularExpression exp = QRegularExpression();
QString val = value.toString();
if (param.getName() == "full") {
exp.setPattern(this->getFullPattern());
} else {
exp.setPattern(this->getPattern());
}
if (exp.match(val).hasMatch()) {
return ErrorMsg();
}
return ErrorMsg(param.getName(), "Value is not a valid email address.");
}
QString EmailValidator::getPattern() const {
return pattern;
}
void EmailValidator::setPattern(const QString &value) {
pattern = value;
}
QString EmailValidator::getFullPattern() const {
return fullPattern;
}
void EmailValidator::setFullPattern(const QString &value) {
fullPattern = value;
}
src/validators/emailvalidator.h
public:
EmailValidator();
ErrorMsg validateParam(QVariant value, Param param) const final override;
QString getPattern() const;
void setPattern(const QString &value);
QString getFullPattern() const;
void setFullPattern(const QString &value);
protected:
QString pattern =
QStringLiteral("/^[a-zA-Z0-9!#$%&\'*+\\/=?^_`{|}~-]+(?:\\\\.[a-zA-Z0-9!#$%&\'*+\\\\/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$/");
QString fullPattern =
QStringLiteral("/^[^@]*<[a-zA-Z0-9!#$%&'*+\\\\/=?^_`{|}~-]+(?:\\.[a-zA-Z0-9!#$%&\'*+\\\\/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?>$/");
};
}
#endif // EMAILVALIDATOR_H

Auch abrufbar als: Unified diff