Classes for data validation
new WsjcppValidatorStringRegexpBase("testre", "^[a-zA-Z]+$")
- validate value by regular expressionnew WsjcppValidatorStringListBase("lang", {"en", "de", "ru"})
- validate value from a listnew WsjcppValidatorEmail()
- validate format emailnew WsjcppValidatorUUID()
- validate format uuidnew WsjcppValidatorStringLength(1,100)
- validate min length and max lengthnew WsjcppValidatorJWT()
- validate format of JWTnew WsjcppValidatorDate()
- validate format date like 'YYYY-MM-DD'new WsjcppValidatorTimeH24()
- validate format date like 'HH:mm:ss' (24 hours)new WsjcppValidatorDateTime()
- validate format date like 'YYYY-MM-DD\THH:mm:ss'new WsjcppValidatorURL()
- validate format of urlnew WsjcppValidatorBase64()
- validate format of base64new WsjcppValidatorNumber()
- validate format of numbernew WsjcppValidatorHex()
- validate hex valuenew WsjcppValidatorIntegerMinValue(1)
- validate integer min valuenew WsjcppValidatorIntegerMaxValue(100)
- validate integer max value
WsjcppValidators::isValidDate(const std::string &sValue, std::string &sError)
WsjcppValidators::isValidTimeH24(const std::string &sValue, std::string &sError)
WsjcppValidators::isValidDomainName(const std::string &sValue, std::string &sError)
WsjcppValidators::isValidBase64(const std::string &sValue, std::string &sError)
WsjcppValidators::isValidIPv4(const std::string &sValue, std::string &sError)
WsjcppValidators::isValidIPv6(const std::string &sValue, std::string &sError)
Just include this files:
- src.wsjcpp/nlohmann_json/json.hpp
- src/wsjcpp_validators.h
- src/wsjcpp_validators.cpp
$ wsjcpp install https://github.com/wsjcpp/wsjcpp-validators:master
WsjcppValidatorUUID *pValidatorUUID = new WsjcppValidatorUUID();
std::string sError = "";
if (!pValidatorUUID->isValid("abcdef01-ABCD-EF23-1000-000000000001", sError)) {
std::cout << sError << std::endl;
}
class WsjcppValidatorUUID : public WsjcppValidatorStringRegexpBase {
public:
WsjcppValidatorUUID()
: WsjcppValidatorStringRegexpBase(
"uuid", // name
"^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"
) {
TAG = "WsjcppValidatorUUID";
}
};