in reply to how should i test whether a string contains between 6 and 20 letters and numbers
It’s not shortness that counts, it’s matching closely what you intend the code to mean. Your original code is not very good because you don’t mean “check if it’s between 6 and 20 letters, numbers and underscores, but make sure it has no underscores.” You mean “check that it’s between 6 and 20 letters and numbers,” so that’s what the code should do:
print( ( $s =~ m{ \A [[:alnum:]]{6,20} \z }x ) ? "success" : "invalid +string" );
Makeshifts last the longest.
|
|---|