utils: fix condition on namespace and task names

The condition was rejecting hyphens while it should accept them. The
condition is rewritten in a more readable way.