Revision 2cfe6214
Von Christian Ehringfeld vor mehr als 9 Jahren hinzugefügt
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
email validator