Can any one suggest me how to validate strings separated by dot (.) in QT basically just like package name in java,
My code goes like this
QRegExp rx("^[\\w]+[^\\.{0,1}\\w+$]*$");
rx.setCaseSensitivity(Qt::CaseInsensitive);
return rx.exactMatch(package);
but I am getting wrong results
Ex:
com.me.test // valid
com.me.he. // invalid
.com.me.he // invalid
com..me.me // invalid
Thats because of your wrong use of a character class. Characters that are between square brackets are a character class, so
[^\\.{0,1}\\w+$]*
is a negated character class, because it starts with a ^
. This class will match any character that is not one of those characters: ".{},01+$" or that is not in \w
.
What you want sounds more like
^\\w+(\\.\\w+)*$
See it here on Regexr
And by the way, you don't need the CaseInsensitive
option, because you don't have explicitly written letters in your regex.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With