Skip to content

Instantly share code, notes, and snippets.

@aaronlelevier
Created July 22, 2014 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronlelevier/4eea7dc5f916292f5369 to your computer and use it in GitHub Desktop.
Save aaronlelevier/4eea7dc5f916292f5369 to your computer and use it in GitHub Desktop.
zip code length custom django validator
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