6#include "validatordigits_p.h"
30 int _length = d->extractInt(c, params, d->length, &ok);
39 if ((_length > 0) && (v.
length() != _length)) {
42 "ValidatorDigits: Validation failed for value \"%s\" in field %s at "
43 "%s::%s: does not contain exactly %i digit(s).",
46 qPrintable(c->controllerName()),
47 qPrintable(c->actionName()),
55 "ValidatorDigits: Validation failed for value \"%s\" in field %s at %s::%s: "
56 "does not only contain digits.",
59 qPrintable(c->controllerName()),
60 qPrintable(c->actionName()));
75 const ushort &uc = ch.unicode();
76 if (!((uc > 47) && (uc < 58))) {
82 if (valid && (length > 0) && (length !=
value.length())) {
94 const int _length = errorData.
toInt();
99 "Cutelyst::ValidatorDigits",
"Must contain exactly %n digit(s).",
"", _length);
101 error = c->
translate(
"Cutelyst::ValidatorDigits",
"Must only contain digits.");
106 error = c->
translate(
"Cutelyst::ValidatorDigits",
107 "The “%1” field must contain exactly %n digit(s).",
113 error = c->
translate(
"Cutelyst::ValidatorDigits",
114 "The “%1” field must only contain digits.")
QString translate(const char *context, const char *sourceText, const char *disambiguation=nullptr, int n=-1) const
QString genericValidationError(Context *c, const QVariant &errorData=QVariant()) const override
Returns a generic error if validation failed.
~ValidatorDigits() override
Deconstructs the digits validator.
ValidatorDigits(const QString &field, const QVariant &length=-1, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey=QString())
Constructs a new digits validator.
QString label(Context *c) const
Returns the human readable field label used for generic error messages.
QString field() const
Returns the name of the field to validate.
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 ...
ValidatorRule(const QString &field, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey=QString())
Constructs a new ValidatorRule with the given parameters.
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.
static bool validate(const QString &value, int length=-1)
Returns true if value only contains digits.
The Cutelyst namespace holds all public Cutelyst API.
QMultiMap< QString, QString > ParamsMultiMap
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
bool isEmpty() const const
void setValue(const T &value)
int toInt(bool *ok) const const
Stores custom error messages and the input field label.
Contains the result of a single input parameter validation.