Validating with QLineEdit InputMask

Found this very confusing …

When I set an InputMask for a QLineEdit to “A9A 9A9” which should enable an entry that works with Canadian Postal Codes and then input for the first character as a number the entry is shifted to position 2 instead of being rejected. If I continue with another number the oiriginal is now shifted to position 5 and the current is 2.

Not sure if this is a bug but it leads to a mess to say the least…

The documentation says an input mask of “A9A 9A9” stipulates the first character entered should be Alphabetic and is required. So… I would expect the entry to be rejected not shifted.

Appreciate any input / suggestions / corrections

Resolved this by removing the InputMask.

Instead I added a Regular Expression as the validator for the Postal Code Widget and connected the textEdited event where I add a space to the edited text and flipped all the Alpha characters to upper case.

Regular Expression: very cryptic in my books but it works !

postal_validator = QRegularExpressionValidator(QRegularExpression(“[A-z]\d{1}[A-z] \d{1}[A-z]\d{1}”))