Honza Kr�l wrote:
Hi Ramdas,
the "Right Way (tm)" how to solve this using newforms is:

1) subclass Field to create a field representing (and validating) username:

class UserField( forms.Field ):
 def clean( self, value ):
   do what you must to verify username, throw validation error if you
are not satisfied with the data

I'd just like to point out that subclassing isn't the only way to add custom validation to a field, you can also implement the clean_FIELDNAME method on your form, or override the forms clean(), this is how I've done it:

class RegistrationForm(forms.Form):
  username = forms.RegexField(r'^[a-zA-Z0-9_]{3,30}$',
                              max_length = 30)
  <- rest of the fields here ->

  def clean_username(self):
    <- additional validation code here ->
    <- raise forms.ValidationError if data is invalid ->


-+ enlight +-

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to