Comment by int_19h
If you restrict the input to ASCII, then it makes sense to talk about "string length" in this manner. But we're not talking about Unicode strings at all then.
If you do allow Unicode characters in whatever it is you're validating, then your approach is almost certainly wrong for some valid input.