This question has been around for half a decade, therefore, updating my question, I must explain that I at least nod to the past, where some functions may be missing.
The easiest way to handle bullets in forms these days is to simply use django.models.SlugField . It will check itself for you and implies that this field is an index.
If you are not using this on a model, you can still use the same validator that SlugField uses:
from django.core.validators import validate_slug slug = forms.CharField(..., validators=[validate_slug])
If you just want to do an off-screen check or write your own validator, you can use a similar method to pull out the definition of a valid Django pool. This is just a compiled regex that uses validate_slug above:
from django.core.validators import slug_re if slug_re.match(...): ...
I can’t imagine that this will change, but if you stick to Django’s slime idea, you’ll ensure consistency if Django changes one day.
Oli
source share