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

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::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::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 bool Cutelyst::ValidatorDomain::validate (const QString &value, bool checkDNS, Diagnose *diagnose=nullptr, QString *extractedValue=nullptr)
 Returns true if value is a valid fully qualified domain name.
 
static bool Cutelyst::ValidatorCharNotAllowed::validate (const QString &value, const QString &forbiddenChars, QChar *foundChar=nullptr)
 Returns true if value does not contain any of the forbideden characters.
 
static int Cutelyst::ValidatorPwQuality::validate (const QString &value, const QVariant &options=QVariant(), const QString &oldPassword=QString(), const QString &user=QString())
 Returns the password quality score for value.
 
static bool Cutelyst::ValidatorIp::validate (const QString &value, Constraints constraints=NoConstraint)
 Returns true if value is a valid IP address within the constraints.
 
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::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::ValidatorDigits::validate (const QString &value, qsizetype length=-1)
 Returns true if value only contains digits.
 

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 ValidatorEmail::validate ( const QString email,
Category  threshold = RFC5321,
Options  options = NoOption,
QList< Diagnose > *  diagnoses = nullptr 
)
static
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 1724 of file validatoremail.cpp.

◆ validate() [2/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 38 of file validatoraccepted.cpp.

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

Referenced by Cutelyst::ValidatorAccepted::validate().

◆ validate() [3/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 45 of file validatoralpha.cpp.

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

Referenced by Cutelyst::ValidatorAlpha::validate().

◆ validate() [4/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 44 of file validatoralphadash.cpp.

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

Referenced by Cutelyst::ValidatorAlphaDash::validate().

◆ validate() [5/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 45 of file validatoralphanum.cpp.

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

Referenced by Cutelyst::ValidatorAlphaNum::validate().

◆ validate() [6/12]

bool ValidatorDomain::validate ( const QString value,
bool  checkDNS,
Diagnose diagnose = nullptr,
QString extractedValue = nullptr 
)
static
Parameters
valueThe value to validate.
checkDNSIf true, a DNS lookup will be performed to check if the domain name exists in the domain name system.
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 26 of file validatordomain.cpp.

References QDnsLookup::A, QDnsLookup::AAAA, QDnsLookup::abort(), QList::at(), QString::at(), QString::chop(), QObject::connect(), Cutelyst::ValidatorDomain::DashEnd, Cutelyst::ValidatorDomain::DashStart, Cutelyst::ValidatorDomain::DigitStart, Cutelyst::ValidatorDomain::DNSTimeout, QList::empty(), Cutelyst::ValidatorDomain::EmptyLabel, QString::endsWith(), QDnsLookup::error, QEventLoop::exec(), QDnsLookup::finished(), QString::fromLatin1(), QDnsLookup::hostAddressRecords(), Cutelyst::ValidatorDomain::InvalidChars, Cutelyst::ValidatorDomain::InvalidLabelCount, Cutelyst::ValidatorDomain::InvalidTLD, QString::isEmpty(), Qt::KeepEmptyParts, Cutelyst::ValidatorDomain::LabelTooLong, QList::last(), QString::length(), QDnsLookup::lookup(), Cutelyst::ValidatorDomain::MissingDNS, QDnsLookup::NoError, QDnsLookup::OperationCancelledError, QEventLoop::quit(), QTimer::singleShot, QList::size(), QString::size(), QString::split(), QString::startsWith(), QUrl::toAce(), QString::toLower(), Cutelyst::ValidatorDomain::TooLong, QChar::unicode(), Cutelyst::ValidatorDomain::Valid, and Cutelyst::ValidatorRule::value().

Referenced by Cutelyst::ValidatorDomain::validate().

◆ validate() [7/12]

bool ValidatorCharNotAllowed::validate ( const QString value,
const QString forbiddenChars,
QChar foundChar = nullptr 
)
static
Parameters
valueThe value to validate.
forbiddenCharsThe list of forbidden characters.
foundCharIf set, it will contain the first found chararacter that is forbidden.
Returns
true if the value does not contain any of the forbiddenChars

Definition at line 20 of file validatorcharnotallowed.cpp.

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

Referenced by Cutelyst::ValidatorCharNotAllowed::validate().

◆ validate() [8/12]

int ValidatorPwQuality::validate ( const QString value,
const QVariant options = QVariant(),
const QString oldPassword = QString(),
const QString user = QString() 
)
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 Cutelyst::ValidatorPwQuality::validate().

◆ validate() [9/12]

bool ValidatorIp::validate ( const QString value,
Constraints  constraints = NoConstraint 
)
static

◆ 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 25 of file validatorfilesize.cpp.

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

Referenced by Cutelyst::ValidatorFileSize::validate().

◆ validate() [11/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 72 of file validatordigitsbetween.cpp.

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

Referenced by Cutelyst::ValidatorDigitsBetween::validate().

◆ validate() [12/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 59 of file validatordigits.cpp.

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

Referenced by Cutelyst::ValidatorDigits::validate().