> What is the "general way" to add your own validation to forms under > the newforms framework? > > Subclassing and adding in your clean_* methods? Using decorators or > the such around existing validation? Adding your own custom Field > objects and setting their "clean" methods?
My understanding (easily wrong, and appreciating correction if so) is that they are divergent concepts, each of which serves its own purpose. The clean_* methods are used for *cleaning* the data. Thus, you might have a textbox for a phone number. Cleaning that might involve stripping it down to purely the number. Thus, the user could enter "(800)555-1212" or "800-555-1212" or "800.555.1212" or perhaps even "800-DJANGO1". These should be "cleaned" to their normalized representation of "8005551212" (or "8003526461"). Likewise, one might have a monitary field where the user might type something like "$3,141.59" in the field and you really want to clean it to just "3141.59". The validators associated with the model should then ensure that this cleaned value is also a valid value. Perhaps you don't allow phone numbers with a "900" area code (usually pay-through-the-nose costs-per-minute associated with them). Perhaps you want to ensure that the phone number is "local" as defined by a set of given area-codes. Or perhaps your money field is intended to be a cost, so you want to validate that it's not a negative number. However, it's also my understanding that the clean_* methods should also catch any validator errors. I don't know if this goes on behind the covers, or if it happens automatically. However, that's what I undertand the distinction to be. Perhaps one of the framework gurus could shed light on "the way it should be done"... -tim --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---