Friday, February 13, 2015

Nice pattern for model with validation baked in

# from http://stackoverflow.com/a/19131360/456878
class PhoneModel(models.Model):
phone_regex = RegexValidator(regex=r'^\+?1?\d{9,15}$',
message="Phone number must be entered in the format: '+999999999'. Up to 15 digits allowed.")
phone_number = models.CharField(validators=[phone_regex], blank=True)
http://stackoverflow.com/a/19131360/456878





No comments:

Post a Comment