quart-imp/docs/_md/v1/quart_imp_auth-is_username_valid.md

58 lines
1.0 KiB
Markdown
Raw Permalink Normal View History

2024-08-16 15:09:07 +01:00
```
Menu = quart_imp.auth/is_username_valid
Title = is_username_valid - quart_imp.auth
```
```python
from quart_imp.auth import is_username_valid
```
```python
is_username_valid(
username: str,
allowed: t.Optional[t.List[t.Literal["all", "dot", "dash", "under"]]] = None
) -> bool
```
---
Checks if a username is valid.
Valid usernames can only include letters,
numbers, ., -, and _ but cannot begin or end with
the last three mentioned.
##### Example "all":
```python
is_username_valid("username", allowed=["all"])
```
Output:
```text
username : WILL PASS : True
user.name : WILL PASS : True
user-name : WILL PASS : True
user_name : WILL PASS : True
_user_name : WILL PASS : False
```
##### Example "dot", "dash":
```python
is_username_valid("username", allowed=["dot", "dash"])
```
Output:
```text
username : WILL PASS : True
user.name : WILL PASS : True
user-name : WILL PASS : True
user-name.name : WILL PASS : True
user_name : WILL PASS : False
_user_name : WILL PASS : False
.user.name : WILL PASS : False
```