6#include "validatorregularexpression_p.h"
11 const QRegularExpression ®ex,
13 const QString &defValKey)
14 :
ValidatorRule(*new ValidatorRegularExpressionPrivate(field, regex, messages, defValKey))
27 const QString v =
value(params);
29 if (d->regex.isValid()) {
31 if (v.contains(d->regex)) {
32 result.
value.setValue(v);
35 qCDebug(C_VALIDATOR).noquote().nospace()
36 <<
debugString(c) <<
" value \"" << v <<
"\" does not match " << d->regex;
43 qCWarning(C_VALIDATOR).noquote().nospace()
44 <<
debugString(c) <<
" the regular expression is not valid: " << d->regex.errorString();
51 const QVariant &errorData)
const
55 const QString _label =
label(c);
56 if (_label.isEmpty()) {
57 error = c->
translate(
"Cutelyst::ValidatorRegularExpression",
58 "Does not match the desired format.");
61 error = c->
translate(
"Cutelyst::ValidatorRegularExpression",
62 "The “%1” field does not match the desired format.")
QString translate(const char *context, const char *sourceText, const char *disambiguation=nullptr, int n=-1) const
<Cutelyst/Plugins/Utils/validatorregularexpression.h>
ValidatorReturnType validate(Context *c, const ParamsMultiMap ¶ms) const override
Performs the validation and returns the result.
~ValidatorRegularExpression() override
Deconstructs the regex validator.
ValidatorRegularExpression(const QString &field, const QRegularExpression ®ex, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey=QString())
Constructs a new regex validator.
QString genericValidationError(Context *c, const QVariant &errorData=QVariant()) const override
Returns a generic error message if validation failed.
Base class for all validator rules.
QString label(Context *c) const
Returns the human readable field label used for generic error messages.
void defaultValue(Context *c, ValidatorReturnType *result) const
I a defValKey has been set in the constructor, this will try to get the default value from the stash ...
QString value(const ParamsMultiMap ¶ms) const
Returns the value of the field from the input params.
QString validationDataError(Context *c, const QVariant &errorData=QVariant()) const
Returns an error message if any validation data is missing or invalid.
QString validationError(Context *c, const QVariant &errorData=QVariant()) const
Returns a descriptive error message if validation failed.
QString debugString(Context *c) const
Returns a string that can be used for debug output if validation fails.
The Cutelyst namespace holds all public Cutelyst API.
QMultiMap< QString, QString > ParamsMultiMap
Stores custom error messages and the input field label.
Contains the result of a single input parameter validation.