Validate Input Against Length Bounds
Problem statement
For this exercise, validate a text input against a supplied length rule. Return true exactly when the number of characters in text is at least minLength and at most maxLength; otherwise return false.
- Both endpoints are inclusive.
- The text contains only printable ASCII characters. Spaces and punctuation each count as one character.
- Measure the original text without trimming, changing case or interpreting markup.
- The supplied bounds are valid:
0 <= minLength <= maxLength.
This is the practice validation predicate for one input value. The source did not specify a validation rule, UI framework or event-wiring interface.
Function
validateInputLength(text: String, minLength: int, maxLength: int) → booleanExamples
Example 1
text = "hello"minLength = 3maxLength = 5return = trueThe text has five characters, so it satisfies the inclusive interval from three through five.
Example 2
text = ""minLength = 1maxLength = 4return = falseThe empty text has length zero, below the supplied minimum of one.
Constraints
0 <= text.length <= 10000.- Every text character has an ASCII code from
32through126. 0 <= minLength <= maxLength <= 10000.