Skip to content

wsjcpp/wsjcpp-validators

Repository files navigation

wsjcpp-validators

Build Status Github Stars Github Stars Github Forks

Classes for data validation

Completed classes

  • new WsjcppValidatorStringRegexpBase("testre", "^[a-zA-Z]+$") - validate value by regular expression
  • new WsjcppValidatorStringListBase("lang", {"en", "de", "ru"}) - validate value from a list
  • new WsjcppValidatorEmail() - validate format email
  • new WsjcppValidatorUUID() - validate format uuid
  • new WsjcppValidatorStringLength(1,100) - validate min length and max length
  • new WsjcppValidatorJWT() - validate format of JWT
  • new 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 url
  • new WsjcppValidatorBase64() - validate format of base64
  • new WsjcppValidatorNumber() - validate format of number
  • new WsjcppValidatorHex() - validate hex value
  • new WsjcppValidatorIntegerMinValue(1) - validate integer min value
  • new WsjcppValidatorIntegerMaxValue(100) - validate integer max value

Completed static functions

  • 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)

Integrate to your project

Just include this files:

  • src.wsjcpp/nlohmann_json/json.hpp
  • src/wsjcpp_validators.h
  • src/wsjcpp_validators.cpp

Integrate via wsjcpp

$ wsjcpp install https://github.com/wsjcpp/wsjcpp-validators:master

Example usage

WsjcppValidatorUUID *pValidatorUUID = new WsjcppValidatorUUID();
std::string sError = "";
if (!pValidatorUUID->isValid("abcdef01-ABCD-EF23-1000-000000000001", sError)) {
    std::cout << sError << std::endl;
}

Example for your implementations

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";
        }
};