開発者は、特別なシンボルを格納できるように、アプリケーション開発者に柔軟性を提供したいと思っていたと思います。したがって、モデルレベルで入力を検証する代わりに、フォームで検証されます。フォームはdjango.contrib.auth.form.UserCreationForm内にあります
スニペットはここにあります:
[ユーザー名]フィールドの正規表現を使用した検証を確認できます。
class UserCreationForm(forms.ModelForm):
"""
A form that creates a user, with no privileges, from the given username and
password.
"""
error_messages = {
'duplicate_username': _("A user with that username already exists."),
'password_mismatch': _("The two password fields didn't match."),
}
username = forms.RegexField(label=_("Username"), max_length=30,
regex=r'^[\w.@+-]+$',
help_text = _("Required. 30 characters or fewer. Letters, digits and "
"@/./+/-/_ only."),
error_messages = {
'invalid': _("This value may contain only letters, numbers and "
"@/./+/-/_ characters.")})
password1 = forms.CharField(label=_("Password"),
widget=forms.PasswordInput)
password2 = forms.CharField(label=_("Password confirmation"),
widget=forms.PasswordInput,
help_text = _("Enter the same password as above, for verification."))