cutelyst 5.0.1
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
Rules

Classes providing rules to validate input data. More...

Collaboration diagram for Rules:

Classes

class  Cutelyst::ValidatorAccepted
 Checks if a field is available and has a specific value. More...
class  Cutelyst::ValidatorAfter
 Checks if a date, time or datetime is after a comparison value. More...
class  Cutelyst::ValidatorAlpha
 Validates an input field for only alphabetic content. More...
class  Cutelyst::ValidatorAlphaDash
 Checks a value for only alpha-numeric content and dashes and underscores. More...
class  Cutelyst::ValidatorAlphaNum
 Checks a value for only alpha-numeric content. More...
class  Cutelyst::ValidatorBefore
 Checks if a date, time or datetime is before a comparison value. More...
class  Cutelyst::ValidatorBetween
 Checks if a value or text length is between a minimum and maximum value. More...
class  Cutelyst::ValidatorBoolean
 Checks if a value can be casted into a boolean. More...
class  Cutelyst::ValidatorCharNotAllowed
 Validates an input field for not allowed characters. More...
class  Cutelyst::ValidatorConfirmed
 Checks for a confirmation input field. More...
class  Cutelyst::ValidatorDate
 Checks if the input data is a valid date. More...
class  Cutelyst::ValidatorDateTime
 Checks if the input data is a valid datetime. More...
class  Cutelyst::ValidatorDifferent
 Checks if two values are different. More...
class  Cutelyst::ValidatorDigits
 Checks for digits only with optional length check. More...
class  Cutelyst::ValidatorDigitsBetween
 Checks for digits only with a length between min and max. More...
class  Cutelyst::ValidatorDomain
 Checks if the value of the input field contains a FQDN according to RFC 1035. More...
class  Cutelyst::ValidatorEmail
 Checks if the value is a valid email address according to specific RFCs. More...
class  Cutelyst::ValidatorFileSize
 Checks if the input field contains a valid file size string like 1.5 GB. More...
class  Cutelyst::ValidatorFilled
 The field under validation must not be empty when it is present. More...
class  Cutelyst::ValidatorIn
 Checks if the field value is one from a list of values. More...
class  Cutelyst::ValidatorInteger
 Checks if the value is an integer. More...
class  Cutelyst::ValidatorIp
 Checks if the field value is a valid IP address. More...
class  Cutelyst::ValidatorJson
 Checks if the inut data is valid JSON. More...
class  Cutelyst::ValidatorMax
 Checks if a value is not bigger or longer than a maximum value. More...
class  Cutelyst::ValidatorMin
 Checks if a value is not smaller or shorter than a maximum value. More...
class  Cutelyst::ValidatorNotIn
 Checks if the field value is not one from a list of values. More...
class  Cutelyst::ValidatorNumeric
 Checks if the field under validation could be casted into a numeric value. More...
class  Cutelyst::ValidatorPresent
 The field under validation must be present in input data but can be empty. More...
class  Cutelyst::ValidatorPwQuality
 Validates an input field with libpwquality to check password quality. More...
class  Cutelyst::ValidatorRegularExpression
 The field under validation must match the given regular expression. More...
class  Cutelyst::ValidatorRequired
 Checks if a field is available and not empty. More...
class  Cutelyst::ValidatorRequiredIf
 The field under validation must be present and not empty if the other field is equal to any value in a list. More...
class  Cutelyst::ValidatorRequiredIfStash
 The field under validation must be present and not empty if the content of a stash key is equal to one from a list. More...
class  Cutelyst::ValidatorRequiredUnless
 The field under validation must be present and not empty unless the other field is equal to any value in the list. More...
class  Cutelyst::ValidatorRequiredUnlessStash
 The field under validation must be present and not empty unless the content of a stash key is equal to a value in a list. More...
class  Cutelyst::ValidatorRequiredWith
 The field under validation must be present and not empty only if any of the other specified fields is present. More...
class  Cutelyst::ValidatorRequiredWithAll
 The field under validation must be present and not empty only if all of the other specified fields are present. More...
class  Cutelyst::ValidatorRequiredWithout
 The field under validation must be present and not empty only if any of the other specified fields is not present. More...
class  Cutelyst::ValidatorRequiredWithoutAll
 The field under validation must be present and not empty only when all of the other specified fields are not present. More...
class  Cutelyst::ValidatorSame
 The given field must match the field under validation. More...
class  Cutelyst::ValidatorSize
 The field under validation must have a size matching the given value. More...
class  Cutelyst::ValidatorTime
 Checks if the input data is a valid time. More...
class  Cutelyst::ValidatorUrl
 The field under validation must be a valid URL. More...

Functions

static bool Cutelyst::ValidatorAccepted::validate (const QString &value)
 Returns true if the value is equal to yes, on, 1, or true.
static bool Cutelyst::ValidatorAlpha::validate (const QString &value, bool asciiOnly=false)
 Returns true if value only contains alphabetic characters.
static bool Cutelyst::ValidatorAlphaDash::validate (const QString &value, bool asciiOnly=false)
 Returns true if the value only contains alpha-numeric characters, dashes and underscores.
static bool Cutelyst::ValidatorAlphaNum::validate (const QString &value, bool asciiOnly=false)
 Returns true if value only contains alpha-numeric characters.
static std::optional< QCharCutelyst::ValidatorCharNotAllowed::validate (const QString &value, const QString &forbiddenChars)
 Returns true if value does not contain any of the forbideden characters.
static bool Cutelyst::ValidatorDigits::validate (const QString &value, qsizetype length=-1)
 Returns true if value only contains digits.
static bool Cutelyst::ValidatorDigitsBetween::validate (const QString &value, int min, int max)
 Returns true if value only contains digits and has a length between min and max.
static bool Cutelyst::ValidatorDomain::validate (const QString &value, Diagnose *diagnose=nullptr, QString *extractedValue=nullptr)
 Returns true if value is a valid fully qualified domain name.
static bool Cutelyst::ValidatorEmail::validate (const QString &email, Category threshold=RFC5321, Options options=NoOption, QList< Diagnose > *diagnoses=nullptr)
 Returns true if email is a valid address according to the Category given in the threshold.
static bool Cutelyst::ValidatorFileSize::validate (const QString &value, double min=-1, double max=-1, Option option=NoOption, const QLocale &locale=QLocale(), double *fileSize=nullptr)
 Returns true if value is a valid file size string.
static bool Cutelyst::ValidatorIp::validate (const QString &value, Constraints constraints=NoConstraint)
 Returns true if value is a valid IP address within the constraints.
static int Cutelyst::ValidatorPwQuality::validate (const QString &value, const QVariant &options={}, const QString &oldPassword={}, const QString &user={})
 Returns the password quality score for value.
static void Cutelyst::ValidatorDomain::validateCb (const QString &value, Options options, std::function< void(Diagnose diagnose, const QString &extractedValue)> cb)
 Checks if value is a vaid fully qualified domain name and writes the result to the callback cb.
static void Cutelyst::ValidatorEmail::validateCb (const QString &email, Category threshold, Options options, std::function< void(bool isValid, const QString &cleanedEmail, const QList< Diagnose > &diagnoses)> cb)
 Checks if the email is a valid address according to the Category given in the threshold.

Detailed Description

All validator rule classes are derived from ValidatorRule and are meant to be used as part of Validator. Read the documentation of Validator to learn more about how to use the Validator and the rules. If you want to write your own validator rule, create a new class that is derived from ValidatorRule and reimplement the validate function.

There are three constructor arguments that are common to almost all validator rules: the name of the field to validate (mandatory), a struct containing translatable ValidatorMessages (optional) and a stash key name that contains a default value if the input field is not available (optional available where it makes sense).

Some validators export their validation logic in a static member function so that it can be used without creating a Validator.

Function Documentation

◆ validate() [1/12]

bool ValidatorAccepted::validate ( const QString & value)
static

Returns true if the value is equal to yes, on, 1, or true, otherwise returns false.

Definition at line 49 of file validatoraccepted.cpp.

References Qt::CaseInsensitive, QStringList::contains(), and Cutelyst::ValidatorRule::value().

Referenced by ~ValidatorAccepted(), validate(), and validateCb().

◆ validate() [2/12]

bool ValidatorAlpha::validate ( const QString & value,
bool asciiOnly = false )
static
Parameters
valueThe value to validate.
asciiOnlyIf true, only ASCII characters are allowed.
Returns
true if value only contains alphabetic characters

Definition at line 51 of file validatoralpha.cpp.

References Cutelyst::ValidatorRule::value().

Referenced by ~ValidatorAlpha(), validate(), and validateCb().

◆ validate() [3/12]

bool ValidatorAlphaDash::validate ( const QString & value,
bool asciiOnly = false )
static
Parameters
valueThe value to validate as it is.
asciiOnlyIf true, only ASCII characters are allowed.
Returns
true if the value only contains alpha-numeric characters, dashes and underscores

Definition at line 52 of file validatoralphadash.cpp.

References Cutelyst::ValidatorRule::value().

Referenced by ~ValidatorAlphaDash(), validate(), and validateCb().

◆ validate() [4/12]

bool ValidatorAlphaNum::validate ( const QString & value,
bool asciiOnly = false )
static
Parameters
valueThe value to validate as it is.
asciiOnlyIf true, only ASCII characters are allowed.
Returns
true if the value only contains alpha-numeric characters

Definition at line 51 of file validatoralphanum.cpp.

References Cutelyst::ValidatorRule::value().

Referenced by ~ValidatorAlphaNum(), validate(), and validateCb().

◆ validate() [5/12]

std::optional< QChar > ValidatorCharNotAllowed::validate ( const QString & value,
const QString & forbiddenChars )
static
Parameters
valueThe value to validate.
forbiddenCharsThe list of forbidden characters.
Returns
the first found chararacter that is forbidden, or has_value == false if not found

Definition at line 20 of file validatorcharnotallowed.cpp.

References QString::end(), and Cutelyst::ValidatorRule::value().

Referenced by ~ValidatorCharNotAllowed(), validate(), and validateCb().

◆ validate() [6/12]

bool ValidatorDigits::validate ( const QString & value,
qsizetype length = -1 )
static

Note that this function will return true for an empty value if the length check is disabled.

Parameters
valueThe value to validate as it is.
lengthExact length of the digits, defaults to -1. A value lower 1 disables the length check.
Returns
true if the value only contains digits

Definition at line 64 of file validatordigits.cpp.

References QChar::isDigit(), and Cutelyst::ValidatorRule::value().

Referenced by ~ValidatorDigits(), validate(), and validateCb().

◆ validate() [7/12]

bool ValidatorDigitsBetween::validate ( const QString & value,
int min,
int max )
static

Nothe that this might return true for an empty value if 0 is between min and max.

Parameters
valueThe value to validate as it is.
minMinimum length of the digits.
maxMaximum length of the digits.
Returns
true if value string only contains digits and has a length between min and max, otherwise it returns false.

Definition at line 79 of file validatordigitsbetween.cpp.

References QChar::isDigit(), and Cutelyst::ValidatorRule::value().

Referenced by ~ValidatorDigitsBetween(), validate(), and validateCb().

◆ validate() [8/12]

bool ValidatorDomain::validate ( const QString & value,
Diagnose * diagnose = nullptr,
QString * extractedValue = nullptr )
static
Note
Since Cutelyst 5.0.0, this will not perform any DNS lookup. For DNS lookups, use ValidatorDomain::validateCb()
Parameters
valueThe value to validate.
diagnoseOptional pointer to a variable that will be filled with the Diagnose that describes the error if validation fails.
extractedValueOptional pointer to a variable that will contain the validated domain converted into ACE puny code.
Returns
true if the value is a valid domain name.

Definition at line 27 of file validatordomain.cpp.

References QList::at(), QString::at(), DashEnd, DashStart, DigitStart, QList::empty(), EmptyLabel, QString::fromLatin1(), InvalidChars, InvalidLabelCount, InvalidTLD, QString::isEmpty(), Qt::KeepEmptyParts, LabelTooLong, QList::last(), QString::length(), QList::size(), QString::size(), QString::split(), QString::startsWith(), QUrl::toAce(), QString::toLower(), TooLong, QChar::unicode(), Valid, and Cutelyst::ValidatorRule::value().

Referenced by ~ValidatorDomain(), validate(), and validateCb().

◆ validate() [9/12]

bool ValidatorEmail::validate ( const QString & email,
Category threshold = RFC5321,
Options options = NoOption,
QList< Diagnose > * diagnoses = nullptr )
static
Note
Since Cutelyst 5.0.0 this will not perform any DNS lookup, even if ValidatorEmail::CheckDNS has been set to the options. For DNS lookups use validateCb().
Parameters
[in]emailThe address to validate.
[in]thresholdThe threshold category that limits the diagnose that is accepted as valid.
[in]optionsOptions for the validation process.
[out]diagnosesIf not a nullptr, this will contain a list of all issues found by the check, ordered from the highest to the lowest.
Returns
true if email is a valid address according to the Category given in the threshold.

Definition at line 1769 of file validatoremail.cpp.

References CheckDNS.

◆ validate() [10/12]

bool ValidatorFileSize::validate ( const QString & value,
double min = -1,
double max = -1,
Option option = NoOption,
const QLocale & locale = QLocale(),
double * fileSize = nullptr )
static
Parameters
[in]valueThe value to validate.
[in]minOptional minimum size. Use a number lower 0 to disable the check.
[in]maxOptional maximum size. Use a number lower 0 to disable the check.
[in]optionOption to use when validating and generating the fileSize.
[in]localeThe locale to use when validating the input value.
[out]fileSizeOptional pointer to a double variable that will contain the extracted file size if validation succeeded.
Returns
true if value is a valid file size string.
Since
Cutelyst 2.0.0

Definition at line 26 of file validatorfilesize.cpp.

References QString::append(), QLocale::decimalPoint(), ForceBinary, ForceDecimal, QString::isEmpty(), OnlyBinary, OnlyDecimal, QLocale::toDouble(), and Cutelyst::ValidatorRule::value().

Referenced by ~ValidatorFileSize(), validate(), and validateCb().

◆ validate() [11/12]

bool ValidatorIp::validate ( const QString & value,
Constraints constraints = NoConstraint )
static
Parameters
valueThe value to validate.
constraintsOptional validation constraints.
Returns
true if value is a valid IP address within the constraints.

Definition at line 57 of file validatorip.cpp.

References IPv4Only, QAbstractSocket::IPv4Protocol, IPv6Only, NoConstraint, NoMultiCast, NoPrivateRange, NoReservedRange, and Cutelyst::ValidatorRule::value().

Referenced by ~ValidatorIp(), validate(), and validateCb().

◆ validate() [12/12]

int ValidatorPwQuality::validate ( const QString & value,
const QVariant & options = {},
const QString & oldPassword = {},
const QString & user = {} )
static
Parameters
valueThe value to validate.
options<a hrefd=#options">Options for libpwquality.
oldPasswordOptional old password used for some checks.
userOptional user name used for some checks.
Returns
the password quality score, everything below 0 is an error, everything >= 0 is a quality score where 0-30 is low, 30-60 medium and 60-100 high quality. For errors you can use ValidatorPwQuality::errorString() to get a human readable string explaining the return value.

Definition at line 31 of file validatorpwquality.cpp.

References QByteArray::constData(), QList::data(), QByteArray::isEmpty(), QString::isEmpty(), QVariant::isValid(), QMetaType::QString, QMetaType::QVariantMap, QList::size(), QVariant::toMap(), QVariant::toString(), QString::toUtf8(), QVariant::typeId(), and Cutelyst::ValidatorRule::value().

Referenced by ~ValidatorPwQuality(), validate(), and validateCb().

◆ validateCb() [1/2]

void ValidatorDomain::validateCb ( const QString & value,
Options options,
std::function< void(Diagnose diagnose, const QString &extractedValue)> cb )
static
Since
Cutelyst 5.0.0
Parameters
valueThe value to validate.
optionsOptions to use for the validation.
cbCallback funcion that will be called for the result.

Definition at line 168 of file validatordomain.cpp.

References QDnsLookup::A, QDnsLookup::AAAA, QDnsLookup::abort(), CheckAAAARecord, CheckARecord, CheckDNS, QObject::connect(), DNSError, DNSTimeout, QDnsLookup::finished(), MissingDNS, QDnsLookup::NoError, QDnsLookup::OperationCancelledError, QTimer::singleShot, Valid, validate(), and Cutelyst::ValidatorRule::value().

Referenced by ~ValidatorDomain(), and validateCb().

◆ validateCb() [2/2]

void ValidatorEmail::validateCb ( const QString & email,
Category threshold,
Options options,
std::function< void(bool isValid, const QString &cleanedEmail, const QList< Diagnose > &diagnoses)> cb )
static
Parameters
emailThe address to validate.
thresholdThe threshold category that limits the diagnose that is accepted as valid.
optionsOptions for the validation process.
cbCallback function that will be called after validation. isValid will be true if the email is valid, diagnoses will contain a list of all issues found by the check, ordered from the highest to the lowest.
Since
Cutelyst 5.0.0

Definition at line 1789 of file validatoremail.cpp.

References QDnsLookup::A, QDnsLookup::abort(), CheckDNS, QObject::connect(), DnsError, DnsErrorTimeout, DnsMxDisabled, DnsNoRecordFound, DnsWarnNoMxRecord, QDnsLookup::finished(), QDnsLookup::MX, QDnsLookup::NoError, QDnsLookup::NotFoundError, QDnsLookup::OperationCancelledError, RFC5321TLD, RFC5321TLDNumeric, and QTimer::singleShot.

Referenced by validateCb().