Cutelyst  2.3.0
Classes | Functions

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::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 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 emptly 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 when any of the other specified fields are 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 yes, on, 1, or true. More...
 
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. More...
 
static bool Cutelyst::ValidatorDigits::validate (const QString &value, int length=-1)
 Returns true if value only contains digits. More...
 
static bool Cutelyst::ValidatorAlphaNum::validate (const QString &value, bool asciiOnly=false)
 Returns true if value only contains alpha-numeric characters. More...
 
static bool Cutelyst::ValidatorAlphaDash::validate (const QString &value, bool asciiOnly=false)
 Returns true if the value only contains alpha-numeric characters, dashes and underscores. More...
 
static bool Cutelyst::ValidatorAlpha::validate (const QString &value, bool asciiOnly=false)
 Returns true if value only contains alphabetic characters. More...
 
static bool Cutelyst::ValidatorIp::validate (const QString &value, Constraints constraints=NoConstraint)
 Returns true if value is a valid IP address within the constraints. More...
 
static bool Cutelyst::ValidatorDomain::validate (const QString &value, bool checkDNS, Diagnose *diagnose=nullptr, QString *extractedValue=nullptr)
 Returns true if value is a valid domain name. More...
 
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. More...
 
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. More...
 
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. More...
 

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 almos 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/11]

bool ValidatorAccepted::validate ( const QString &  value)
static
Parameters
valueThe value to validate.
Returns
true if the value is yes, on, 1, or true.

Definition at line 50 of file validatoraccepted.cpp.

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

◆ validate() [2/11]

bool ValidatorDigitsBetween::validate ( const QString &  value,
int  min,
int  max 
)
static
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. Nothe that this might return true for an empty value if 0 is between min and max.

Definition at line 78 of file validatordigitsbetween.cpp.

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

◆ validate() [3/11]

bool ValidatorDigits::validate ( const QString &  value,
int  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 67 of file validatordigits.cpp.

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

◆ validate() [4/11]

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 57 of file validatoralphanum.cpp.

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

◆ validate() [5/11]

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 56 of file validatoralphadash.cpp.

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

◆ validate() [6/11]

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 the value only contains alphabetic characters

Definition at line 56 of file validatoralpha.cpp.

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

◆ validate() [7/11]

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 59 of file validatorip.cpp.

References Cutelyst::ValidatorIp::IPv4Only, Cutelyst::ValidatorIp::IPv6Only, Cutelyst::ValidatorIp::NoConstraint, Cutelyst::ValidatorIp::NoMultiCast, Cutelyst::ValidatorIp::NoPrivateRange, Cutelyst::ValidatorIp::NoReservedRange, and Cutelyst::ValidatorIp::PublicOnly.

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

◆ validate() [8/11]

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 37 of file validatordomain.cpp.

References Cutelyst::ValidatorDomain::DashEnd, Cutelyst::ValidatorDomain::DashStart, Cutelyst::ValidatorDomain::DigitStart, Cutelyst::ValidatorDomain::DNSTimeout, Cutelyst::ValidatorDomain::EmptyLabel, Cutelyst::ValidatorDomain::InvalidChars, Cutelyst::ValidatorDomain::InvalidLabelCount, Cutelyst::ValidatorDomain::InvalidTLD, Cutelyst::ValidatorDomain::LabelTooLong, Cutelyst::ValidatorDomain::MissingDNS, Cutelyst::ValidatorDomain::TooLong, Cutelyst::ValidatorDomain::Valid, and Cutelyst::ValidatorRule::value().

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

◆ validate() [9/11]

int ValidatorPwQuality::validate ( const QString &  value,
const QVariant &  options = QVariant(),
const QString &  oldPassword = QString(),
const QString &  user = QString() 
)
static
Parameters
valueThe value to validate.
optionsOptions 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. You can use ValidatorPwQuality::errorString() to get a human readable string explaining the return value.

Definition at line 36 of file validatorpwquality.cpp.

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

◆ validate() [10/11]

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

References Cutelyst::ValidatorFileSize::ForceBinary, Cutelyst::ValidatorFileSize::ForceDecimal, Cutelyst::ValidatorFileSize::OnlyBinary, and Cutelyst::ValidatorFileSize::OnlyDecimal.

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

◆ validate() [11/11]

static bool Cutelyst::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.

Referenced by Cutelyst::ValidatorEmail::categoryString().