Add Visione backend foundation
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
#include "common/Validation.h"
|
||||
|
||||
#include <regex>
|
||||
|
||||
namespace visione::validation
|
||||
{
|
||||
bool hasString(const Json::Value &body, const std::string &key)
|
||||
{
|
||||
return body.isMember(key) && body[key].isString() &&
|
||||
!body[key].asString().empty();
|
||||
}
|
||||
|
||||
bool hasNumber(const Json::Value &body, const std::string &key)
|
||||
{
|
||||
return body.isMember(key) && body[key].isNumeric();
|
||||
}
|
||||
|
||||
std::vector<std::string> missingStrings(
|
||||
const Json::Value &body,
|
||||
std::initializer_list<const char *> keys)
|
||||
{
|
||||
std::vector<std::string> missing;
|
||||
for (const auto *key : keys)
|
||||
{
|
||||
if (!hasString(body, key))
|
||||
{
|
||||
missing.emplace_back(key);
|
||||
}
|
||||
}
|
||||
return missing;
|
||||
}
|
||||
|
||||
bool isValidEmail(const std::string &email)
|
||||
{
|
||||
static const std::regex pattern(R"(^[^@\s]+@[^@\s]+\.[^@\s]+$)");
|
||||
return std::regex_match(email, pattern);
|
||||
}
|
||||
|
||||
bool isValidFiscalCode(const std::string &fiscalCode)
|
||||
{
|
||||
static const std::regex pattern(R"(^[A-Za-z0-9]{16}$)");
|
||||
return std::regex_match(fiscalCode, pattern);
|
||||
}
|
||||
} // namespace visione::validation
|
||||
|
||||
Reference in New Issue
Block a user