6 #include "validatordigits_p.h" 14 :
ValidatorRule(*new ValidatorDigitsPrivate(field, length, messages, defValKey))
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 validationError(Context *c, const QVariant &errorData=QVariant()) const
Returns a descriptive error message if validation failed.
Checks for digits only with optional length check.
~ValidatorDigits() override
Deconstructs the digits validator.
Stores custom error messages and the input field label.
QString genericValidationError(Context *c, const QVariant &errorData=QVariant()) const override
Returns a generic error if validation failed.
int toInt(bool *ok) const const
bool isEmpty() const const
QString translate(const char *context, const char *sourceText, const char *disambiguation=nullptr, int n=-1) const
QString validationDataError(Context *c, const QVariant &errorData=QVariant()) const
Returns an error message if any validation data is missing or invalid.
The Cutelyst namespace holds all public Cutelyst API.
Base class for all validator rules.
QString label(Context *c) const
Returns the human readable field label used for generic error messages.
static bool validate(const QString &value, int length=-1)
Returns true if value only contains digits.
QString value(const ParamsMultiMap ¶ms) const
Returns the value of the field from the input params.
ValidatorDigits(const QString &field, const QVariant &length=-1, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey=QString())
Constructs a new digits validator.
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
qsizetype length() const const
QString field() const
Returns the name of the field to validate.
Contains the result of a single input parameter validation.
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 ...