validate_initial¶
- pyrcs.utils.validate_initial(initial, as_is=False)[source]¶
Validates if a value is a single ASCII letter.
- Parameters:
initial (str) – The input value to validate, which is expected to be a string representing a single letter.
as_is (bool) – If
as_is=True, the function returns the letter in its original case; ifas_is=False(default), the letter is returned in uppercase.
- Returns:
The validated initial letter.
- Return type:
str
- Raises:
ValueError – If the input is not a single ASCII letter.
TypeError – If the input is not a string.
Examples:
>>> from pyrcs.utils import validate_initial >>> validate_initial('x') 'X' >>> validate_initial('x', as_is=True) 'x' >>> validate_initial('xyz') Traceback (most recent call last): ... ... ValueError: 'xyz' is invalid; it must be a single letter (A-Z, a-z).