(self)
Validate Character fields
Validate Character fields
Validate Character fields
def validate_text_fields(self):
        """Validate Character fields """
        bool_map = {'false': False, 'true': True}
        # Default pattern matches any alphanumeric string with a given length
        default_pattern = r"^\w{1,20}$"

        for field, item in self.json_data.items():
            val = self.cleaned_data.get(field)

            # Validate text fields
            if (val is None) or (item.get("display") != TEXTBOX):
                continue

            # Acceptable regex pattern
            regex_pattern = item.get("regex", default_pattern)

            if re.fullmatch(regex_pattern, val) is None:
                msg = f"{field} : contains invalid patterns. Valid pattern:{regex_pattern}."
                raise forms.ValidationError(msg)
def validate_text_fields ( self ) : bool_map = { 'false' : False , 'true' : True } # Default pattern matches any alphanumeric string with a given length default_pattern = r"^\w{1,20}$" for field , item in self . json_data . items ( ) : val = self . cleaned_data . get ( field ) # Validate text fields if ( val is None ) or ( item . get ( "display" ) != TEXTBOX ) : continue # Acceptable regex pattern regex_pattern = item . get ( "regex" , default_pattern ) if re . fullmatch ( regex_pattern , val ) is None : msg = f"{field} : contains invalid patterns. Valid pattern:{regex_pattern}." raise forms . ValidationError ( msg )