draconisplusplus/include/rfl/patterns.hpp

38 lines
1.1 KiB
C++
Raw Normal View History

2024-05-31 22:59:00 -04:00
#ifndef RFL_PATTERNS_HPP_
#define RFL_PATTERNS_HPP_
#include "Pattern.hpp"
#include "Validator.hpp"
namespace rfl {
2024-06-08 14:10:59 -04:00
/// This pattern only matches alphanumeric characters.
using AlphaNumeric = Pattern<R"(^[a-zA-Z0-9]*$)", "AlphaNumeric">;
2024-05-31 22:59:00 -04:00
2024-06-08 14:10:59 -04:00
/// This pattern will match valid Base64 encoded strings with or without
/// padding.
2024-06-16 00:13:15 -04:00
using Base64Encoded = Pattern<R"(^[A-Za-z0-9+/]*(={0,2})?$)", "Base64Encoded">;
2024-05-31 22:59:00 -04:00
2024-06-08 14:10:59 -04:00
/// This pattern will match email addresses.
2024-06-16 00:13:15 -04:00
using Email = Pattern<R"(^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$)", "Email">;
2024-05-31 22:59:00 -04:00
2024-06-08 14:10:59 -04:00
using UUIDv1 = Pattern<
2024-06-16 00:13:15 -04:00
R"(^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-1[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$)",
"UUIDv1">;
2024-05-31 22:59:00 -04:00
2024-06-08 14:10:59 -04:00
using UUIDv2 = Pattern<
2024-06-16 00:13:15 -04:00
R"(^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-2[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$)",
"UUIDv2">;
2024-05-31 22:59:00 -04:00
2024-06-08 14:10:59 -04:00
using UUIDv3 = Pattern<
2024-06-16 00:13:15 -04:00
R"(^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-3[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$)",
"UUIDv3">;
2024-05-31 22:59:00 -04:00
2024-06-08 14:10:59 -04:00
using UUIDv4 = Pattern<
2024-06-16 00:13:15 -04:00
R"(^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$)",
"UUIDv4">;
2024-05-31 22:59:00 -04:00
2024-06-08 14:10:59 -04:00
} // namespace rfl
2024-05-31 22:59:00 -04:00
#endif