6#include "validatorcharnotallowed_p.h"
11 const QString &forbiddenChars,
13 const QString &defValKey)
14 :
ValidatorRule(*new ValidatorCharNotAllowedPrivate(field, forbiddenChars, messages, defValKey))
21 const QString &forbiddenChars,
26 for (
const QChar &forbiddenChar : forbiddenChars) {
27 if (
value.contains(forbiddenChar)) {
30 *foundChar = forbiddenChar;
46 const QString v =
value(params);
48 if (Q_LIKELY(!d->forbiddenChars.isEmpty())) {
51 result.
value.setValue(v);
56 qCWarning(C_VALIDATOR).noquote() <<
debugString(c) <<
"Empty validation data";
68 const QChar foundChar = errorData.toChar();
70 const QString _label =
label(c);
71 if (_label.isEmpty()) {
76 return c->
qtTrId(
"cutelyst-valcharnotallowed-genvalerr")
77 .arg(d->forbiddenChars, QString(foundChar));
83 return c->
qtTrId(
"cutelyst-valcharnotallowed-genvalerr-label")
84 .arg(_label, d->forbiddenChars, QString(foundChar));
89 const QVariant &errorData)
const
92 const QString _label =
label(c);
93 if (_label.isEmpty()) {
95 return c->
qtTrId(
"cutelyst-valcharnotallowed-genvaldataerr");
98 return c->
qtTrId(
"cutelyst-valcharnotallowed-genvaldataerr-label").arg(_label);
QString qtTrId(const char *id, int n=-1) const
Validates an input field for not allowed characters.
QString genericValidationDataError(Context *c, const QVariant &errorData=QVariant()) const override
QString genericValidationError(Context *c, const QVariant &errorData=QVariant()) const override
~ValidatorCharNotAllowed() override
ValidatorCharNotAllowed(const QString &field, const QString &forbiddenChars, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey=QString())
Base class for all validator rules.
QString validationError(Context *c, const QVariant &errorData={}) const
QString label(Context *c) const
QString validationDataError(Context *c, const QVariant &errorData={}) const
void defaultValue(Context *c, ValidatorReturnType *result) const
QString value(const ParamsMultiMap ¶ms) const
QString debugString(Context *c) const
QMultiMap< QString, QString > ParamsMultiMap
static bool validate(const QString &value, const QString &forbiddenChars, QChar *foundChar=nullptr)
Returns true if value does not contain any of the forbideden characters.
The Cutelyst namespace holds all public Cutelyst API.
Stores custom error messages and the input field label.
Contains the result of a single input parameter validation.