6#include "validatordigitsbetween_p.h"
14 const QString &defValKey)
15 :
ValidatorRule(*new ValidatorDigitsBetweenPrivate(field, min, max, messages, defValKey))
27 const QString v =
value(params);
31 int _min = d->extractInt(c, params, d->min, &ok);
34 qCWarning(C_VALIDATOR).noquote()
35 <<
debugString(c) <<
"Invalid minimum length comparison data";
38 _max = d->extractInt(c, params, d->max, &ok);
41 qCWarning(C_VALIDATOR).noquote()
42 <<
debugString(c) <<
"Invalid maximum length comparison data";
49 qCWarning(C_VALIDATOR).noquote()
50 <<
debugString(c) <<
"Minimum comparison length" << _min <<
"is larger than"
51 <<
"maximum comparison length" << _max;
58 result.
value.setValue(v);
61 qCDebug(C_VALIDATOR).noquote()
62 <<
debugString(c) <<
"Length of" << v.length() <<
"is not between" << _min <<
"and"
63 << _max <<
"and/or input value contains non-digit characters";
77 for (
const QChar &ch :
value) {
78 const ushort &uc = ch.unicode();
79 if (!((uc >= ValidatorRulePrivate::ascii_0) && (uc <= ValidatorRulePrivate::ascii_9))) {
85 if (valid && ((
value.length() < min) || (
value.length() > max))) {
96 const QVariantList list = errorData.toList();
97 const QString min = list.at(0).toString();
98 const QString max = list.at(1).toString();
99 const QString _label =
label(c);
101 if (_label.isEmpty()) {
102 error = c->
translate(
"Cutelyst::ValidatorDigitsBetween",
103 "Must contain between %1 and %2 digits.")
107 error = c->
translate(
"Cutelyst::ValidatorDigitsBetween",
108 "The “%1” field must contain between %2 and %3 digits.")
109 .arg(_label, min, max);
QString translate(const char *context, const char *sourceText, const char *disambiguation=nullptr, int n=-1) const
<Cutelyst/Plugins/Utils/validatordigitsbetween.h>
~ValidatorDigitsBetween() override
Deconstructs the digits between validator.
ValidatorDigitsBetween(const QString &field, const QVariant &min, const QVariant &max, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey=QString())
Constructs a new digits between validator.
QString genericValidationError(Context *c, const QVariant &errorData=QVariant()) const override
Returns a generic error 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.
static bool validate(const QString &value, int min, int max)
Returns true if value only contains digits and has a length between min and max.
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.