Versatile string validation
10
3
$begingroup$
I passed a technical test the other day, one part included a cheap string validation and I am wondering this can be further improved to be more versatile to requirement changes. The requirements were something like that Create a Validate method, which accepts a string and returns true if it's valid and false if it's not. A string is valid if it satisfies the rules below: The string must be at least 6 characters long and not exceed 16 characters. The string must contain only letters, numbers and optionally one hyphen (-). The string must start with a letter, and must not end with a hyphen. For example, validate("Michelle Belle"); would return false because it contains a space. My solution was like that: public static class ComparableExtensi