19 #include "validatorregularexpression_p.h"
21 using namespace Cutelyst;
24 ValidatorRule(*new ValidatorRegularExpressionPrivate(field, regex, messages, defValKey))
40 if (d->regex.isValid()) {
46 qCDebug(C_VALIDATOR,
"ValidatorRegularExpression: Validation failed for field %s at %s::%s because value does not match the following regular expression: %s", qPrintable(
field()), qPrintable(c->controllerName()), qPrintable(c->actionName()), qPrintable(d->regex.pattern()));
53 qCWarning(C_VALIDATOR,
"ValidatorRegularExpression: the regular expression for the field %s at %s::%s is not valid: %s", qPrintable(
field()), qPrintable(c->controllerName()), qPrintable(c->actionName()), qPrintable(d->regex.errorString()));
65 error = c->
translate(
"Cutelyst::ValidatorRegularExpression",
"Does not match the desired format.");
68 error = c->
translate(
"Cutelyst::ValidatorRegularExpression",
"The “%1” field does not match the desired format.").
arg(_label);
QString field() const
Returns the name of the field to validate.
ValidatorReturnType validate(Context *c, const ParamsMultiMap ¶ms) const override
Performs the validation and returns the result.
QString label(Context *c) const
Returns the human readable field label used for generic error messages.
QString genericValidationError(Context *c, const QVariant &errorData=QVariant()) const override
Returns a generic error message if validation failed.
Stores custom error messages and the input field label.
ValidatorRegularExpression(const QString &field, const QRegularExpression ®ex, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey=QString())
Constructs a new regex validator.
QString value(const ParamsMultiMap ¶ms) const
Returns the value of the field from the input params.
QString validationError(Context *c, const QVariant &errorData=QVariant()) const
Returns a descriptive error message if validation failed.
Base class for all validator rules.
void defaultValue(Context *c, ValidatorReturnType *result, const char *validatorName) const
I a defValKey has been set in the constructor, this will try to get the default value from the stash ...
bool contains(QChar ch, Qt::CaseSensitivity cs) const
void setValue(const T &value)
QString translate(const char *context, const char *sourceText, const char *disambiguation=nullptr, int n=-1) const
Contains the result of a single input parameter validation.
QString validationDataError(Context *c, const QVariant &errorData=QVariant()) const
Returns an error message if any validation data is missing or invalid.
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const
~ValidatorRegularExpression() override
Deconstructs the regex validator.
The field under validation must match the given regular expression.