我是Python/Django的新手,我试图在模型的字段中插入电话号码。在
我在我的模型.py是
from django.db import models
from django.core.validators import *
telephone = RegexValidator(r'^\d+$', 'Only numeric characters are allowed.')
class Registration(models.Model):
mobile_telephone = models.PositiveIntegerField(max_length=18, validators=[telephone, MaxLengthValidator])
代码表单.py在
^{pr2}$我试过了模型.py对于IntegerField、CharField和PositiveIntegerField,但是它们都不允许在字段的开头使用0。在
我做错什么了?在
谢谢
在模型中使用
CharField
。正则表达式将确保只允许使用数字字符。在相关问题 更多 >
编程相关推荐