📜  在 django 模型中使用正则表达式验证器 - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:42.193000             🧑  作者: Mango

代码示例1
from django.core.validators import RegexValidator
from django.db import models
PHONE_NUMBER_REGEX = RegexValidator(r'^[+]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-\s\./0-9]*$', 'only valid email is required')
class SomeClass(models.Model):
  phone =  models.CharField(max_length=14, validators=[PHONE_REGEX])