19 #include "validatorregularexpression_p.h"
24 ValidatorRule(*new ValidatorRegularExpressionPrivate(field, regex, messages, defValKey))
38 const QString v =
value(params);
40 if (d->regex.isValid()) {
42 if (v.contains(d->regex)) {
43 result.
value.setValue<QString>(v);
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()));
63 const QString _label =
label(c);
64 if (_label.isEmpty()) {
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);
QMap< QString, QString > ParamsMultiMap
Stores custom error messages and the input field label.
QString value(const ParamsMultiMap ¶ms) const
Returns the value of the field from the input params.
QString label(Context *c) const
Returns the human readable field label used for generic error messages.
QString validationError(Context *c, const QVariant &errorData=QVariant()) const
Returns a descriptive error message if validation failed.
ValidatorReturnType validate(Context *c, const ParamsMultiMap ¶ms) const override
Performs the validation and returns the result.
QString genericValidationError(Context *c, const QVariant &errorData=QVariant()) const override
Returns a generic error message if validation failed.
Base class for all validator rules.
~ValidatorRegularExpression() override
Deconstructs the regex validator.
The field under validation must match the given regular expression.
QString field() const
Returns the name of the field to validate.
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.
The Cutelyst namespace holds all public Cutelyst API.
ValidatorRegularExpression(const QString &field, const QRegularExpression ®ex, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey=QString())
Constructs a new regex validator.
QString validationDataError(Context *c, const QVariant &errorData=QVariant()) const
Returns an error message if any validation data is missing or invalid.
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 ...