Skip to content

Instantly share code, notes, and snippets.

@poseidon4o
Created May 16, 2021 16:24
Show Gist options
  • Save poseidon4o/658cedaa71aee5bef86ac7a0689fb4f2 to your computer and use it in GitHub Desktop.
Save poseidon4o/658cedaa71aee5bef86ac7a0689fb4f2 to your computer and use it in GitHub Desktop.
#include <cctype>
#include <cstring>
#include <iostream>
typedef int (*Validator)(int);
bool isValidRegistration(char reg[9]) {
const Validator validators[9] = {isupper, isupper, isdigit, isdigit, isdigit, isdigit, isupper, isupper };
const int len = strlen(reg);
const Validator *check = len == 8 ? validators : validators + 1;
for (int c = 0; c < len; c++) {
if (!check[c](reg[c])) {
return false;
}
}
return true;
}
int main() {
char reg[6][9] = {"C1234AB", "XY1111YX", "111145", "ABC34DEF", "ABCDEF", "C11D"};
for (int c = 0; c < sizeof(reg) / sizeof(reg[0]); c++) {
std::cout << reg[c] << " - " << isValidRegistration(reg[c]) << '\n';
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment