0

I would like to allow my users to register using greek characters.

I added in my admin.py file the following code. Is the regular expression correct ( regex=r'^[\w\p{Greek}-]+$',) ? I would like to allow greek and english characters

from django.contrib.auth.models import User
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.forms import UserCreationForm, UserChangeForm

class MyUserCreationForm(UserCreationForm):
  username = forms.RegexField(
    label='Username',
    max_length=30,
    regex=r'^[\w\p{Greek}-]+$',
    help_text = 'Required. 30 characters or fewer. Alphanumeric characters only (letters, digits, hyphens and underscores).',
    error_message = 'This value must contain only letters, numbers, hyphens and underscores.')

class MyUserChangeForm(UserChangeForm):
  username = forms.RegexField(
    label='Username',
    max_length=30,
    regex=r'^[\w\p{Greek}-]+$',
    help_text = 'Required. 30 characters or fewer. Alphanumeric characters only (letters, digits, hyphens and underscores).',
    error_message = 'This value must contain only letters, numbers, hyphens and underscores.')

class MyUserAdmin(UserAdmin):
  form = MyUserChangeForm
  add_form = MyUserCreationForm

admin.site.unregister(User)
admin.site.register(User, MyUserAdmin)
glarkou
  • 7,023
  • 12
  • 68
  • 118
  • Yes. Just found the solution but I think it is not correct but it is working! – glarkou Aug 24 '13 at 10:45
  • Do you have any problems, didn't that work for you or what ? – Ibrahim Najjar Aug 24 '13 at 10:46
  • Did you try just using greek letters without configuring anything? Django is really good with language support, I use hebrew characters in my admin site without setting up anything and it works like a charm – yuvi Aug 24 '13 at 11:33

0 Answers0