6#include "validatordigits_p.h"
14 :
ValidatorRule(*new ValidatorDigitsPrivate(field, length, messages, defValKey))
28 const qlonglong _length = ValidatorDigitsPrivate::extractLongLong(c, params, d->length, &ok);
30 qCDebug(C_VALIDATOR).noquote() <<
debugString(c) <<
"Invalid comparison length";
38 if ((_length > 0) && (v.
length() != _length)) {
40 qCDebug(C_VALIDATOR).noquote()
41 <<
debugString(c) <<
"Does not contain exactly" << _length
42 <<
"digits:" << v.
length() <<
"!=" << _length;
48 qCDebug(C_VALIDATOR).noquote().nospace()
49 <<
debugString(c) <<
" Does not only contain digits: \"" << v <<
"\"";
66 bool allDigits = std::ranges::all_of(
value, [](
const QChar &ch) {
return ch.
isDigit(); });
68 return allDigits && ((length <= 0) || (length ==
value.
length()));
74 const int _length = errorData.
toInt();
79 return c->
qtTrId(
"cutelyst-valdigits-genvalerr-length", _length);
82 return c->
qtTrId(
"cutelyst-valdigits-genvalerr");
88 return c->
qtTrId(
"cutelyst-valdigits-genvalerr-length-label", _length).
arg(_label);
92 return c->
qtTrId(
"cutelyst-valdigits-genvalerr-label").
arg(_label);
QString qtTrId(const char *id, int n=-1) const
Checks for digits only with optional length check.
void validateCb(Context *c, const ParamsMultiMap ¶ms, ValidatorRtFn cb) const override
QString genericValidationError(Context *c, const QVariant &errorData=QVariant()) const override
~ValidatorDigits() override
ValidatorDigits(const QString &field, const QVariant &length=-1, const ValidatorMessages &messages={}, const QString &defValKey={})
Base class for all validator rules.
QString validationError(Context *c, const QVariant &errorData={}) const
QString label(const Context *c) const
QString debugString(const Context *c) const
QString validationDataError(Context *c, const QVariant &errorData={}) const
std::function< void(ValidatorReturnType &&result)> ValidatorRtFn
Void callback function for validator rules that processes the ValidatorReturnType.
void defaultValue(Context *c, ValidatorReturnType *result) const
QString value(const ParamsMultiMap ¶ms) const
static bool validate(const QString &value, qsizetype length=-1)
Returns true if value only contains digits.
The Cutelyst namespace holds all public Cutelyst API.
bool isDigit(char32_t ucs4)
QString arg(Args &&... args) const const
bool isEmpty() const const
qsizetype length() const const
void setValue(QVariant &&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.