djangosnippets.org: Latest snippets posted by garywilsonhttps://djangosnippets.org/users/garywilson/2007-04-09T12:03:22.056560-05:00garywilsonuse oldforms validators in newforms forms
2007-04-09T12:03:22.056560-05:00garywilsonhttps://djangosnippets.org/snippets/165/<p>Using the <code>run_oldforms_validators</code> function, you can run oldforms validators in your newforms <code>clean_XXX</code> methods.</p>
<p>Usage example:</p>
<pre><code>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', …</code></pre>
Freely redistributable