19 #include "validatorcharnotallowed_p.h"
21 using namespace Cutelyst;
24 ValidatorRule(*new ValidatorCharNotAllowedPrivate(field, forbiddenChars, messages, defValKey))
38 for (
const QChar &forbiddenChar : forbiddenChars) {
42 *foundChar = forbiddenChar;
59 if (Q_LIKELY(!d->forbiddenChars.isEmpty())) {
67 qCWarning(C_VALIDATOR) <<
"ValidatorCharNotAllowed: Empty validation data for field" <<
field() <<
"at" << c->controllerName() <<
"::" << c->actionName();
84 error = c->
translate(
"Cutelyst::ValidatorCharNotAllowed",
"Must not contain the following characters: “%1”. But contains the following illegal character: “%2”.").
arg(d->forbiddenChars,
QString(foundChar));
86 error = c->
translate(
"Cutelyst::ValidatorCharNotAllowed",
"The text in the “%1“ field must not contain the following characters: “%2“. But contains the following illegal character: “%3”.").
arg(_label, d->forbiddenChars,
QString(foundChar));
98 error = c->
translate(
"Cutelyst::ValidatorCharNotAllowed",
"The list of illegal characters for this field is empty.");
100 error = c->
translate(
"Cutelyst::ValidatorCharNotAllowed",
"The list of illegal characters for the “%1“ field is empty.").
arg(_label);
~ValidatorCharNotAllowed() override
Deconstructs the char not allowed validator.
QString field() const
Returns the name of the field to validate.
QString label(Context *c) const
Returns the human readable field label used for generic error messages.
Stores custom error messages and the input field label.
ValidatorCharNotAllowed(const QString &field, const QString &forbiddenChars, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey=QString())
Constructs a new char not allowed validator.
QString genericValidationDataError(Context *c, const QVariant &errorData=QVariant()) const override
Returns a generic error if the list of forbidden characters is empty.
static bool validate(const QString &value, const QString &forbiddenChars, QChar *foundChar=nullptr)
Returns true if value does not contain any of the charachters in forbiddenChars.
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
Validates an input field for not allowed characters.
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
QString genericValidationError(Context *c, const QVariant &errorData=QVariant()) const override
Returns a generic error message if validation failed.