Special Character Validation
-
I want to do special character validation.
When creating a folder, you need to validate the name.
There are special characters that are limited when creating folders in Windows.QString v("[^\\\/:*?\"<>|]"); this->setValidator(new QRegExpValidator(QRegExp(v)));
I wrote the code like this, but no characters are input.
Is there a way to disable only special characters? -
@IknowQT
It doesn't matter, but why do you start your regular expression with[^\\\\
? That is 2 literal backslashes, the second one achieves nothing inside[^
. For readability/simplicity, might as well be"[^\\/...]"
. You also have*
listed twice. And at least some of your excluded characters are allowed in Windows file/directory names, such as, say,!
or@
. You may forbid them if that is what you wish, but just be aware they are not forbidden characters. A list of genuinely illegal characters (there are only 9 disallowed punctuation ones --- oh, that is what you had in your first attempt) can be found at e.g. https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions. There are also further rules than just illegal characters, e.g. "The filename can't end with a space or a period".It is a shame you persist with
QRegExp
stuff. Unless you are using a pretty old Qt version, you would be better moving toQRegularExpression
, and will require to do so if you upgrade.