Skip to content

InputFilter

An input filter that uses a regular expression to allow or deny/block certain patterns in the input.

属性 ​

名称类型默认值说明
regex_stringstrrequiredA regular expression pattern for the filter. It is recommended to use raw strings (prefix your string with r) for the pattern, ex: r"pattern".
allowboolTrueA boolean value indicating whether to allow or deny/block the matched patterns.
replacement_stringstr''A string used to replace banned/denied patterns.
multilineboolFalseWhether this regular expression matches multiple lines. If the regexp does match multiple lines, the "^" and "$" characters match the beginning and end of lines. If not, the characters match the beginning and end of the input.
case_sensitiveboolTrueWhether this regular expression is case sensitive. If the regular expression is not case sensitive, it will match an input letter with a pattern letter even if the two letters are different case versions of the same letter.
unicodeboolFalseWhether this regular expression uses Unicode mode.
dot_allboolFalseWhether "." in this regular expression matches line terminators. When false, the "." character matches a single character, unless that character terminates a line. When true, then the "." character will match any single character including line terminators. This feature is distinct from multiline. They affect the behavior of different pattern characters, so they can be used together or separately.

Predefined filters ​

NumbersOnlyInputFilter 继承自: InputFilter

Allows only numbers.

属性 ​

名称类型默认值说明
regex_stringstrrequiredA regular expression pattern for the filter. It is recommended to use raw strings (prefix your string with r) for the pattern, ex: r"pattern".
allowboolTrueA boolean value indicating whether to allow or deny/block the matched patterns.
replacement_stringstr''A string used to replace banned/denied patterns.
multilineboolFalseWhether this regular expression matches multiple lines. If the regexp does match multiple lines, the "^" and "$" characters match the beginning and end of lines. If not, the characters match the beginning and end of the input.
case_sensitiveboolTrueWhether this regular expression is case sensitive. If the regular expression is not case sensitive, it will match an input letter with a pattern letter even if the two letters are different case versions of the same letter.
unicodeboolFalseWhether this regular expression uses Unicode mode.
dot_allboolFalseWhether "." in this regular expression matches line terminators. When false, the "." character matches a single character, unless that character terminates a line. When true, then the "." character will match any single character including line terminators. This feature is distinct from multiline. They affect the behavior of different pattern characters, so they can be used together or separately.
TextOnlyInputFilter
继承自: InputFilter

Allows only text.

属性 ​

名称类型默认值说明
regex_stringstrrequiredA regular expression pattern for the filter. It is recommended to use raw strings (prefix your string with r) for the pattern, ex: r"pattern".
allowboolTrueA boolean value indicating whether to allow or deny/block the matched patterns.
replacement_stringstr''A string used to replace banned/denied patterns.
multilineboolFalseWhether this regular expression matches multiple lines. If the regexp does match multiple lines, the "^" and "$" characters match the beginning and end of lines. If not, the characters match the beginning and end of the input.
case_sensitiveboolTrueWhether this regular expression is case sensitive. If the regular expression is not case sensitive, it will match an input letter with a pattern letter even if the two letters are different case versions of the same letter.
unicodeboolFalseWhether this regular expression uses Unicode mode.
dot_allboolFalseWhether "." in this regular expression matches line terminators. When false, the "." character matches a single character, unless that character terminates a line. When true, then the "." character will match any single character including line terminators. This feature is distinct from multiline. They affect the behavior of different pattern characters, so they can be used together or separately.

Usage example ​

python
ft.CupertinoTextField(
    placeholder_text="Only numbers are allowed",
    input_filter=ft.InputFilter(allow=True, regex_string=r"^[0-9]*$", replacement_string="")
)
python
ft.TextField(
    label="Only letters are allowed",
    input_filter=ft.TextOnlyInputFilter()
)

关注我,学习大模型、大数据、Python等热门技术。