Skip to content

Validators

Input validators for enforcing text formatting rules.

Preview

FXValidators

Classes

FXCamelCaseValidator

Bases: QRegularExpressionValidator

Validator for camelCase without special characters or numbers.

This validator ensures input follows camelCase format: starts with a lowercase letter, followed by zero or more groups of an uppercase letter followed by lowercase letters.

Examples:

>>> from qtpy.QtWidgets import QLineEdit
>>> line_edit = QLineEdit()
>>> line_edit.setValidator(FXCamelCaseValidator())

FXCapitalizedLetterValidator

Bases: QValidator

Validator for names that must start with a capital letter and contain only letters.

This validator ensures the first character is uppercase and all characters are alphabetic.

Examples:

>>> from qtpy.QtWidgets import QLineEdit
>>> line_edit = QLineEdit()
>>> line_edit.setValidator(FXCapitalizedLetterValidator())

Methods:

Name Description
fixup

Automatically capitalize the first letter.

validate

Allow only letters and must start with a capital letter.

fixup

fixup(input_string: str) -> str

Automatically capitalize the first letter.

validate

validate(input_string: str, pos: int)

Allow only letters and must start with a capital letter.

FXLettersUnderscoreValidator

Bases: QRegularExpressionValidator

Validator for letters and underscores, with optional numbers support.

Parameters:

Name Type Description Default

allow_numbers

bool

If True, allows numbers in addition to letters and underscores.

False

parent

Optional[QWidget]

Parent widget.

None

Examples:

>>> from qtpy.QtWidgets import QLineEdit
>>> line_edit = QLineEdit()
>>> line_edit.setValidator(FXLettersUnderscoreValidator(allow_numbers=True))

FXLowerCaseValidator

Bases: QRegularExpressionValidator

Validator for lowercase letters only, with optional numbers and underscores support.

Parameters:

Name Type Description Default

allow_numbers

bool

If True, allows numbers in addition to lowercase letters.

False

allow_underscores

bool

If True, allows underscores in addition to lowercase letters.

False

parent

Optional[QWidget]

Parent widget.

None

Examples:

>>> from qtpy.QtWidgets import QLineEdit
>>> line_edit = QLineEdit()
>>> line_edit.setValidator(FXLowerCaseValidator(allow_numbers=True))