Skip to content

Commit cdde63e

Browse files
authored
forvat: validator-class (#115)
1 parent a755e55 commit cdde63e

1 file changed

Lines changed: 31 additions & 16 deletions

File tree

src/Validator.cpp

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,81 @@
11
#include "Validator.hpp"
22

3-
bool Validator::isValidEmail(const std::string& email) {
3+
bool Validator::isValidEmail(const std::string &email) {
44
const std::regex pattern(R"(([^@\s]+)@([^\s@]+)\.([^\s@]+))");
55
return std::regex_match(email, pattern);
66
}
77

8-
bool Validator::isValidPhone(const std::string& phone) {
8+
bool Validator::isValidPhone(const std::string &phone) {
99
const std::regex pattern(R"(^\+\d{1,15}$)");
1010
return std::regex_match(phone, pattern);
1111
}
1212

13-
void Validator::validateAccountParams(const std::string& email, const std::string& password, const std::string& userId) {
13+
void Validator::validateAccountParams(const std::string &email,
14+
const std::string &password,
15+
const std::string &userId) {
1416
if (!isValidEmail(email)) {
1517
throw std::invalid_argument("Invalid email format.");
1618
}
1719
if (password.length() < 8) {
18-
throw std::invalid_argument("Password must be at least 8 characters long.");
20+
throw std::invalid_argument(
21+
"Password must be at least 8 characters long.");
1922
}
2023
if (userId.empty()) {
2124
throw std::invalid_argument("User ID cannot be empty.");
2225
}
2326
}
2427

25-
void Validator::validateAccountParams(const std::string& email, const std::string& password) {
28+
void Validator::validateAccountParams(const std::string &email,
29+
const std::string &password) {
2630
if (!isValidEmail(email)) {
2731
throw std::invalid_argument("Invalid email format.");
2832
}
2933
if (password.length() < 8) {
30-
throw std::invalid_argument("Password must be at least 8 characters long.");
34+
throw std::invalid_argument(
35+
"Password must be at least 8 characters long.");
3136
}
3237
}
3338

34-
void Validator::validateDatabaseParams(const std::string& databaseId, const std::string& name){
39+
void Validator::validateDatabaseParams(const std::string &databaseId,
40+
const std::string &name) {
3541
std::regex databaseIdPattern("^[a-zA-Z0-9][a-zA-Z0-9._-]{0,35}$");
36-
42+
3743
if (!std::regex_match(databaseId, databaseIdPattern)) {
38-
throw std::invalid_argument("Invalid databaseId. Must start with an alphanumeric character and can contain only alphanumeric characters, periods, hyphens, and underscores, with a max length of 36 characters.");
44+
throw std::invalid_argument(
45+
"Invalid databaseId. Must start with an alphanumeric character and "
46+
"can contain only alphanumeric characters, periods, hyphens, and "
47+
"underscores, with a max length of 36 characters.");
3948
}
4049

4150
if (name.length() > 128) {
42-
throw std::invalid_argument("Invalid name. Must be 128 characters or less.");
51+
throw std::invalid_argument(
52+
"Invalid name. Must be 128 characters or less.");
4353
}
4454
}
4555

46-
47-
void Validator::validateStorageParams(const std::string& bucketId, const std::string& name){
56+
void Validator::validateStorageParams(const std::string &bucketId,
57+
const std::string &name) {
4858
std::regex bucketIdPattern("^[a-zA-Z0-9][a-zA-Z0-9._-]{0,35}$");
4959

5060
if (!std::regex_match(bucketId, bucketIdPattern)) {
51-
throw std::invalid_argument("Invalid bucketId. Must start with an alphanumeric character and can contain only alphanumeric characters, periods, hyphens, and underscores, with a max length of 36 characters.");
61+
throw std::invalid_argument(
62+
"Invalid bucketId. Must start with an alphanumeric character and "
63+
"can contain only alphanumeric characters, periods, hyphens, and "
64+
"underscores, with a max length of 36 characters.");
5265
}
5366

5467
if (name.empty()) {
5568
throw std::invalid_argument("Bucket Name is required field.");
5669
}
5770
}
5871

59-
void Validator::validateStorageParams(const std::string& bucketId){
72+
void Validator::validateStorageParams(const std::string &bucketId) {
6073
std::regex bucketIdPattern("^[a-zA-Z0-9][a-zA-Z0-9._-]{0,35}$");
6174

6275
if (!std::regex_match(bucketId, bucketIdPattern)) {
63-
throw std::invalid_argument("Invalid bucketId. Must start with an alphanumeric character and can contain only alphanumeric characters, periods, hyphens, and underscores, with a max length of 36 characters.");
76+
throw std::invalid_argument(
77+
"Invalid bucketId. Must start with an alphanumeric character and "
78+
"can contain only alphanumeric characters, periods, hyphens, and "
79+
"underscores, with a max length of 36 characters.");
6480
}
65-
6681
}

0 commit comments

Comments
 (0)