Skip to content

Instantly share code, notes, and snippets.

@TSKGunGun
Created October 6, 2021 09:51
Show Gist options
  • Save TSKGunGun/94412748065f6e4527d4bb54fcae15d3 to your computer and use it in GitHub Desktop.
Save TSKGunGun/94412748065f6e4527d4bb54fcae15d3 to your computer and use it in GitHub Desktop.
# Create your models here.
from django.db import models
from django.core.validators import RegexValidator
class NumValidator(RegexValidator):
regex = r'^[0-9]+\Z'
message = "ゼッケンNoは数字のみで入力してください。"
def __call__(self, value):
return super().__call__(value)
class Foo(models.Model):
val = NumValidator()
num = models.CharField(verbose_name="番号", max_length=10, null=False, validators=[val])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment