QLineEdit check for text input {[AZ] [az] [0-9]}

I want to accept a new username from a user in my application. I want the username string to contain only A-Zeither A-Zor 0-9, and have a maximum length of 8. Therefore, I want to check the input from QLineEdit. I looked through the documentation, but I'm corrupted by validators. How can I check mine QLineEditfor this purpose?

+3
source share
1 answer

you can use setInputMask to specify a validation input mask, in your case you can use N or n to allow only characters in AZ, az, 0-9 range, Smth, like this:

lineEdit->setInputMask("nnnnnnnn;_"); // or NNNNNNNN;_
lineEdit->setCursorPosition(0);

QValidator , setValidator. , .

: setMaxLength

lineEdit->setMaxLength(8);

, ,

+7

Source: https://habr.com/ru/post/1796602/


All Articles