Djangophonenumberfield:获取电话号码字段验证模式

2024-10-01 09:32:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在模型中使用django-phonenumber-field。我想欧芹.js在客户端验证模型表单。但是,我找不到用于在服务器端验证PhoneNumberField字段的正则表达式。在

如果可能的话,我真的很想用同样的表达方式。在

这是我的模型和表格:

from phonenumber_field.modelfields import PhoneNumberField

@python_2_unicode_compatible
class CVApplication(Application):
    mobile_phone_number = PhoneNumberField()
    [...]


@parsleyfy
class CVApplicationForm(forms.ModelForm):
    class Meta:
        model = CVApplication
        fields = (
            'mobile_phone_number',
            [...]
        )

    def __init__(self, *args, **kwargs):
        super(CVApplicationForm, self).__init__(*args, **kwargs)
        self.fields['mobile_phone_number'].widget.attrs.update(
            {'data-parsley-pattern': '??????????'}
        )
        [...]

谢谢你的帮助!在


Tags: 模型selfnumberfieldfieldsinitargsphone