Cutelyst  1.5.0
Public Types | Public Member Functions | Protected Member Functions | List of all members
Cutelyst::ValidatorIp Class Reference

Checks if the field value is a valid IP address. More...

#include <validatorip.h>

Inheritance diagram for Cutelyst::ValidatorIp:
Inheritance graph
[legend]

Public Types

enum  Constraint {
  NoConstraint, IPv4Only, IPv6Only, NoPrivateRange,
  NoReservedRange, NoMultiCast, PublicOnly
}
 Acceptable address ranges. More...
 

Public Member Functions

 ValidatorIp (const QString &field, Constraints constraints=NoConstraint, const QString &label=QString(), const QString &customError=QString())
 Constructs a new ip validator. More...
 
 ~ValidatorIp ()
 Deconstructs the ip validator.
 
void setConstraints (Constraints constraints)
 Sets optional validation contraints.
 
QString validate () const override
 Performs the validation and returns an empty QString on success, otherwise an error message.
 
- Public Member Functions inherited from Cutelyst::ValidatorRule
 ValidatorRule (const QString &field, const QString &label=QString(), const QString &customError=QString())
 Constructs a new ValidatorRule with given parameters and parent. More...
 
 ~ValidatorRule ()
 Deconstructs the ValidatorRule.
 
QString field () const
 Returns the name of the field to validate. More...
 
QString label () const
 Returns the human readable field label used for generic error messages. More...
 
ParamsMultiMap parameters () const
 Returns the parameters to validate. More...
 
void setCustomError (const QString &customError)
 Sets a cutom error returned with errorMessage() More...
 
void setCustomParsingError (const QString &custom)
 Sets a custom error message that is shown if parsing of input data fails. More...
 
void setCustomValidationDataError (const QString &custom)
 Sets a custom error message if validation data is invalid or missing. More...
 
void setField (const QString &field)
 Sets the name of the field to validate. More...
 
void setLabel (const QString &label)
 Sets human readable field label for generic error messages. More...
 
void setParameters (const ParamsMultiMap &params)
 Sets the request parameters to validate. More...
 
void setTrimBefore (bool trimBefore)
 Set to false to not trim input value before validation. More...
 
bool trimBefore () const
 Returns true if field value should be trimmed before validation. More...
 
QString value () const
 Returns the field value.
 

Protected Member Functions

 ValidatorIp (ValidatorIpPrivate &dd)
 
QString genericValidationError () const override
 Returns a generic error message.
 
- Protected Member Functions inherited from Cutelyst::ValidatorRule
 ValidatorRule (ValidatorRulePrivate &dd)
 
virtual QString genericParsingError () const
 Returns a generic error message if an error occures while parsing input. More...
 
virtual QString genericValidationDataError () const
 Returns a generic error message if any validation data is missing or invalid. More...
 
QString parsingError () const
 Returns an error message if an error occured while parsing input. More...
 
QString validationDataError () const
 Returns an error message if any validation data is missing or invalid. More...
 
QString validationError () const
 Returns a descriptive error message if validation failed. More...
 

Additional Inherited Members

- Protected Attributes inherited from Cutelyst::ValidatorRule
const QScopedPointer< ValidatorRulePrivate > d_ptr
 

Detailed Description

This uses QHostAddress internally to check if the field contains a valid IP address. You can use the constraints flags to limit the validator to specific address ranges.

If ValidatorRule::trimBefore() is set to true (the default), whitespaces will be removed from the beginning and the end of the input value before validation. If the field's value is empty or if the field is missing in the input data, the validation will succeed without performing the validation itself. Use one of the required validators to require the field to be present and not empty.

See Validator for general usage of validators.

Definition at line 42 of file validatorip.h.

Member Enumeration Documentation

Enumerator
NoConstraint 

No address range limit.

IPv4Only 

Only IPv4 addresses are valid.

IPv6Only 

Only IPv6 addresses are valid.

NoPrivateRange 

Addresses from private networks like 192.168.0.0/12 and fe80::/10 are invalid.

NoReservedRange 

Addresses from reserved networks like 192.88.99.0/24 and 2001:db8::/32 are invalid.

NoMultiCast 

Multicast addresses are invalid.

PublicOnly 

Combines NoPrivateRange, NoReservedRange and NoMultiCast.

Definition at line 48 of file validatorip.h.

Constructor & Destructor Documentation

Cutelyst::ValidatorIp::ValidatorIp ( const QString &  field,
Constraints  constraints = NoConstraint,
const QString &  label = QString(),
const QString &  customError = QString() 
)
Parameters
fieldName of the input field to validate.
constraintOptional validation constraints.
labelHuman readable input field label, used for error messages.
customErrorCustom errror message if validation fails.