Created
July 22, 2014 16:56
-
-
Save aaronlelevier/4eea7dc5f916292f5369 to your computer and use it in GitHub Desktop.
zip code length custom django validator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
from django.core.exceptions import ValidationError | |
def validate_length(value): | |
if len(value) != 5: | |
raise ValidationError('%s is not five digits.' % value) | |
class MyModel(models.Model): | |
five_digit_field = models.IntegerField(validators=[validate_length]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment