djangosnippets.org: Latest snippets tagged with 'validators'https://djangosnippets.org/tags/validators/2012-01-14T20:43:58.387870-06:00models.MultipleEmailField
2012-01-14T20:43:58.387870-06:00ferohttps://djangosnippets.org/snippets/2645/<p>Define validator <code>multiple_email_validator</code> that splits value by commas and calls <code>validate_email</code> validator for each element found.</p>
<p>Then define MultipleEmailField with this default validator and augmented max_length.</p>
<p>Then ... use it!</p>
Freely redistributableuse 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 redistributableNewforms customs validators
2007-03-18T15:52:59.889859-05:00baptistehttps://djangosnippets.org/snippets/115/<p>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. …</p>
Freely redistributable