Snippet List
Using the `run_oldforms_validators` function, you can run oldforms validators in your newforms `clean_XXX` methods.
Usage example:
class PasswordForm(forms.Form):
password = forms.CharField(widget=forms.PasswordInput())
def clean_password(self):
validator_list = [
isStrongPassword,
isValidLength,
SomeValidators(
num_required=3,
validator_list=[hasLower, hasUpper, hasNumeric, hasSpecial],
error_message="Password must contain at least 3 of: lowercase, uppercase, numeric, and/or special characters."
)
]
run_oldforms_validators('password', self, validator_list)
return self.clean_data['password']
Above, `isStrongPassword`, `isValidLength`, etc. are oldforms validators. If you are interested in seeing the implementation of `isStrongPassword`, please see my [Using CrackLib to require stronger passwords](http://gdub.wordpress.com/2006/08/26/using-cracklib-to-require-stronger-passwords/) blog post.
- newforms
- validators
- oldforms
How to proceed to add a custom validator to a newforms field : you just need to create a new class derivated from forms.YourField with a custom clean method. Do not forget the line super(UserField, self).clean(value) ; in our case, it verifies the field attributes : min_length, max_length or required.
More explications (in French) : [des validateurs personnalisés pour Django](http://www.aozeo.com/blog/67-django-newforms-validateurs-personnalises)
3 snippets posted so far.