N
N
nano_e_t_42016-01-21 05:30:43
Flask
nano_e_t_4, 2016-01-21 05:30:43

How to fasten the field validation?

Hello everyone
Who came across, tell me how to file validation of fields based on regexps in flask? In this case, the regular expression must be given by a variable.

operator_name = TextField('operator_name', [Required(),\
    #Regexp(allowed_characters, message = message)])
    Regexp('A-Za-z',message = 'wrong symbol, try again')])

With the variant with a regular expression as an argument, everything is fine. But if the regular expression is supplied by the allowed_character variable, then the debugger throws an exception list' object has no attribute 'match'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Radist_101, 2016-01-21
@Radist_101

Can try to do validation in form method like

def validate_operator_name(self, field):
        if not field.data:
            raise ValidationError("Error!")

where in the method name "def validate_operator_name" operator_name is a form field

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question