我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用django.forms.RegexField()。
def __init__(self, regex, max_length=None, min_length=None, *args, **kwargs): super(RegexField, self).__init__(max_length, min_length, *args, **kwargs) self.regex = regex
def test_should_regex_convert_string(): assert_conversion(forms.RegexField, graphene.String, '[0-9]+')
def clean(self): if 'password' in self.cleaned_data and 'confirm_password' in self.cleaned_data: if self.cleaned_data['password'] != self.cleaned_data['confirm_password']: raise forms.ValidationError(_("The two password fields did not match.")) return self.cleaned_data # class StudentInfoForm(forms.Form): # stud_name = forms.RegexField(required=True, regex=r'^\w+$', label='', max_length=200, widget=forms.TextInput(attrs={'placeholder': "First Name eg: Shiv", 'autofocus':'true'})) # stud_school = forms.RegexField(required=True, regex=r'^\w+$', label='', max_length=200, widget=forms.TextInput(attrs={'placeholder': "Student's School's Name"})) # stud_standard = forms.RegexField(required=True, regex=r'^\w+$', label='', max_length=30, widget=forms.TextInput(attrs={'placeholder': "Student's Standard"})) # stud_div = forms.RegexField(required=True, regex=r'^\w+$', label='', max_length=30, widget=forms.TextInput(attrs={'placeholder': "Student's Division"})) # # date_of_fill = forms.DateField(required=True, input_formats=['%d-%m-%Y'], label='',widget=forms.DateInput(attrs={'placeholder': "Date of Filling", 'type':"date"})) # date_of_birth = forms.DateField(required=True, input_formats=['%d-%m-%Y'], label='', widget=forms.DateInput(attrs={'placeholder': "Date of Birth", 'type':"date"})) # # father_name = forms.CharField(required=True, label='', max_length=200, widget=forms.TextInput(attrs={'placeholder': "Father's Full Name", 'autofocus':'true'})) # father_contact = forms.CharField(required=True, label='', max_length=10, widget=forms.TextInput(attrs={'placeholder': "Eg 98xxxxxxx0"})) # father_email = forms.EmailField(required=True, label='', widget=forms.TextInput(attrs=dict(required=True, max_length=200, placeholder="Father's Email"))) # father_education = forms.CharField(required=True, label='', max_length=200,widget=forms.TextInput(attrs={'placeholder': "Father's Education"})) # father_occupation = forms.CharField(required=True, label='', max_length=200,widget=forms.TextInput(attrs={'placeholder': "Father's Occupation"})) # # mother_name = forms.CharField(required=True, label='', max_length=200, widget=forms.TextInput(attrs={'placeholder': "Mother's Full Name",'autofocus': 'true'})) # mother_contact = forms.CharField(required=True, label='', max_length=10, widget=forms.TextInput(attrs={'placeholder': "Eg 98xxxxxxx0"})) # mother_email = forms.EmailField(required=True, label='', widget=forms.TextInput(attrs=dict(required=True, max_length=200, placeholder="Mother's Email"))) # mother_education = forms.CharField(required=True, label='', max_length=200, widget=forms.TextInput(attrs={'placeholder': "Mother's Education"})) # mother_occupation = forms.CharField(required=True, label='', max_length=200, widget=forms.TextInput(attrs={'placeholder': "Mother's Occupation"})) # # letter_identification = forms.BooleanField() # let_sound_assoc = forms.BooleanField() # spelling = forms.BooleanField() # reading = forms.BooleanField() # comprehension = forms.BooleanField() # composition = forms.BooleanField() # grammar = forms.BooleanField() # # number_identification = forms.BooleanField() # forget_tables = forms.BooleanField() # carry_borr = forms.BooleanField() # frac_dec = forms.BooleanField() # problem_int = forms.BooleanField() # algebra = forms.BooleanField() # # awareness = forms.IntegerField() # acceptance = forms.IntegerField() # active_participation = forms.IntegerField() # emo_support_provided = forms.IntegerField() # strength_awareness = forms.IntegerField() # parenting_style = forms.IntegerField()